|
12 | 12 | //
|
13 | 13 | //===----------------------------------------------------------------------===//
|
14 | 14 |
|
15 |
| -public enum WebAuthnError: Error, Equatable { |
| 15 | +/// An error that occured preparing or processing WebAuthn-related requests. |
| 16 | +public struct WebAuthnError: Error, Hashable { |
| 17 | + enum Reason: Error { |
| 18 | + // MARK: Shared |
| 19 | + case attestedCredentialDataMissing |
| 20 | + case relyingPartyIDHashDoesNotMatch |
| 21 | + case userPresentFlagNotSet |
| 22 | + case invalidSignature |
| 23 | + |
| 24 | + // MARK: AttestationObject |
| 25 | + case userVerificationRequiredButFlagNotSet |
| 26 | + case attestationStatementMustBeEmpty |
| 27 | + case attestationVerificationNotSupported |
| 28 | + |
| 29 | + // MARK: WebAuthnManager |
| 30 | + case invalidUserID |
| 31 | + case unsupportedCredentialPublicKeyAlgorithm |
| 32 | + case credentialIDAlreadyExists |
| 33 | + case invalidRelyingPartyID |
| 34 | + case userVerifiedFlagNotSet |
| 35 | + case potentialReplayAttack |
| 36 | + case invalidAssertionCredentialType |
| 37 | + |
| 38 | + // MARK: ParsedAuthenticatorAttestationResponse |
| 39 | + case invalidAttestationObject |
| 40 | + case invalidAuthData |
| 41 | + case invalidFmt |
| 42 | + case missingAttStmt |
| 43 | + case attestationFormatNotSupported |
| 44 | + |
| 45 | + // MARK: ParsedCredentialCreationResponse |
| 46 | + case invalidCredentialCreationType |
| 47 | + case credentialRawIDTooLong |
| 48 | + |
| 49 | + // MARK: AuthenticatorData |
| 50 | + case authDataTooShort |
| 51 | + case attestedCredentialFlagNotSet |
| 52 | + case extensionDataMissing |
| 53 | + case leftOverBytesInAuthenticatorData |
| 54 | + case credentialIDTooLong |
| 55 | + case credentialIDTooShort |
| 56 | + |
| 57 | + // MARK: CredentialPublicKey |
| 58 | + case badPublicKeyBytes |
| 59 | + case invalidKeyType |
| 60 | + case invalidAlgorithm |
| 61 | + case invalidCurve |
| 62 | + case invalidXCoordinate |
| 63 | + case invalidYCoordinate |
| 64 | + case unsupportedCOSEAlgorithm |
| 65 | + case unsupportedCOSEAlgorithmForEC2PublicKey |
| 66 | + case invalidModulus |
| 67 | + case invalidExponent |
| 68 | + case unsupportedCOSEAlgorithmForRSAPublicKey |
| 69 | + case unsupported |
| 70 | + } |
| 71 | + |
| 72 | + let reason: Reason |
| 73 | + |
| 74 | + init(reason: Reason) { |
| 75 | + self.reason = reason |
| 76 | + } |
| 77 | + |
16 | 78 | // MARK: Shared
|
17 |
| - case attestedCredentialDataMissing |
18 |
| - case relyingPartyIDHashDoesNotMatch |
19 |
| - case userPresentFlagNotSet |
20 |
| - case invalidSignature |
| 79 | + public static let attestedCredentialDataMissing = Self(reason: .attestedCredentialDataMissing) |
| 80 | + public static let relyingPartyIDHashDoesNotMatch = Self(reason: .relyingPartyIDHashDoesNotMatch) |
| 81 | + public static let userPresentFlagNotSet = Self(reason: .userPresentFlagNotSet) |
| 82 | + public static let invalidSignature = Self(reason: .invalidSignature) |
21 | 83 |
|
22 | 84 | // MARK: AttestationObject
|
23 |
| - case userVerificationRequiredButFlagNotSet |
24 |
| - case attestationStatementMustBeEmpty |
25 |
| - case attestationVerificationNotSupported |
| 85 | + public static let userVerificationRequiredButFlagNotSet = Self(reason: .userVerificationRequiredButFlagNotSet) |
| 86 | + public static let attestationStatementMustBeEmpty = Self(reason: .attestationStatementMustBeEmpty) |
| 87 | + public static let attestationVerificationNotSupported = Self(reason: .attestationVerificationNotSupported) |
26 | 88 |
|
27 | 89 | // MARK: WebAuthnManager
|
28 |
| - case invalidUserID |
29 |
| - case unsupportedCredentialPublicKeyAlgorithm |
30 |
| - case credentialIDAlreadyExists |
31 |
| - case invalidRelyingPartyID |
32 |
| - case userVerifiedFlagNotSet |
33 |
| - case potentialReplayAttack |
34 |
| - case invalidAssertionCredentialType |
| 90 | + public static let invalidUserID = Self(reason: .invalidUserID) |
| 91 | + public static let unsupportedCredentialPublicKeyAlgorithm = Self(reason: .unsupportedCredentialPublicKeyAlgorithm) |
| 92 | + public static let credentialIDAlreadyExists = Self(reason: .credentialIDAlreadyExists) |
| 93 | + public static let invalidRelyingPartyID = Self(reason: .invalidRelyingPartyID) |
| 94 | + public static let userVerifiedFlagNotSet = Self(reason: .userVerifiedFlagNotSet) |
| 95 | + public static let potentialReplayAttack = Self(reason: .potentialReplayAttack) |
| 96 | + public static let invalidAssertionCredentialType = Self(reason: .invalidAssertionCredentialType) |
35 | 97 |
|
36 | 98 | // MARK: ParsedAuthenticatorAttestationResponse
|
37 |
| - case invalidAttestationObject |
38 |
| - case invalidAuthData |
39 |
| - case invalidFmt |
40 |
| - case missingAttStmt |
41 |
| - case attestationFormatNotSupported |
| 99 | + public static let invalidAttestationObject = Self(reason: .invalidAttestationObject) |
| 100 | + public static let invalidAuthData = Self(reason: .invalidAuthData) |
| 101 | + public static let invalidFmt = Self(reason: .invalidFmt) |
| 102 | + public static let missingAttStmt = Self(reason: .missingAttStmt) |
| 103 | + public static let attestationFormatNotSupported = Self(reason: .attestationFormatNotSupported) |
42 | 104 |
|
43 | 105 | // MARK: ParsedCredentialCreationResponse
|
44 |
| - case invalidCredentialCreationType |
45 |
| - case credentialRawIDTooLong |
| 106 | + public static let invalidCredentialCreationType = Self(reason: .invalidCredentialCreationType) |
| 107 | + public static let credentialRawIDTooLong = Self(reason: .credentialRawIDTooLong) |
46 | 108 |
|
47 | 109 | // MARK: AuthenticatorData
|
48 |
| - case authDataTooShort |
49 |
| - case attestedCredentialFlagNotSet |
50 |
| - case extensionDataMissing |
51 |
| - case leftOverBytesInAuthenticatorData |
52 |
| - case credentialIDTooLong |
53 |
| - case credentialIDTooShort |
| 110 | + public static let authDataTooShort = Self(reason: .authDataTooShort) |
| 111 | + public static let attestedCredentialFlagNotSet = Self(reason: .attestedCredentialFlagNotSet) |
| 112 | + public static let extensionDataMissing = Self(reason: .extensionDataMissing) |
| 113 | + public static let leftOverBytesInAuthenticatorData = Self(reason: .leftOverBytesInAuthenticatorData) |
| 114 | + public static let credentialIDTooLong = Self(reason: .credentialIDTooLong) |
| 115 | + public static let credentialIDTooShort = Self(reason: .credentialIDTooShort) |
54 | 116 |
|
55 | 117 | // MARK: CredentialPublicKey
|
56 |
| - case badPublicKeyBytes |
57 |
| - case invalidKeyType |
58 |
| - case invalidAlgorithm |
59 |
| - case invalidCurve |
60 |
| - case invalidXCoordinate |
61 |
| - case invalidYCoordinate |
62 |
| - case unsupportedCOSEAlgorithm |
63 |
| - case unsupportedCOSEAlgorithmForEC2PublicKey |
64 |
| - case invalidModulus |
65 |
| - case invalidExponent |
66 |
| - case unsupportedCOSEAlgorithmForRSAPublicKey |
67 |
| - case unsupported |
| 118 | + public static let badPublicKeyBytes = Self(reason: .badPublicKeyBytes) |
| 119 | + public static let invalidKeyType = Self(reason: .invalidKeyType) |
| 120 | + public static let invalidAlgorithm = Self(reason: .invalidAlgorithm) |
| 121 | + public static let invalidCurve = Self(reason: .invalidCurve) |
| 122 | + public static let invalidXCoordinate = Self(reason: .invalidXCoordinate) |
| 123 | + public static let invalidYCoordinate = Self(reason: .invalidYCoordinate) |
| 124 | + public static let unsupportedCOSEAlgorithm = Self(reason: .unsupportedCOSEAlgorithm) |
| 125 | + public static let unsupportedCOSEAlgorithmForEC2PublicKey = Self(reason: .unsupportedCOSEAlgorithmForEC2PublicKey) |
| 126 | + public static let invalidModulus = Self(reason: .invalidModulus) |
| 127 | + public static let invalidExponent = Self(reason: .invalidExponent) |
| 128 | + public static let unsupportedCOSEAlgorithmForRSAPublicKey = Self(reason: .unsupportedCOSEAlgorithmForRSAPublicKey) |
| 129 | + public static let unsupported = Self(reason: .unsupported) |
68 | 130 | }
|
0 commit comments