File tree Expand file tree Collapse file tree 2 files changed +19
-10
lines changed
Sources/WebAuthn/Ceremonies/Registration Expand file tree Collapse file tree 2 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -30,13 +30,20 @@ public struct AuthenticatorAttestationResponse {
30
30
public let attestationObject : [ UInt8 ]
31
31
}
32
32
33
- extension AuthenticatorAttestationResponse : Decodable {
33
+ extension AuthenticatorAttestationResponse : Codable {
34
34
public init ( from decoder: Decoder ) throws {
35
35
let container = try decoder. container ( keyedBy: CodingKeys . self)
36
36
37
37
clientDataJSON = try container. decodeBytesFromURLEncodedBase64 ( forKey: . clientDataJSON)
38
38
attestationObject = try container. decodeBytesFromURLEncodedBase64 ( forKey: . attestationObject)
39
39
}
40
+
41
+ public func encode( to encoder: Encoder ) throws {
42
+ var container = encoder. container ( keyedBy: CodingKeys . self)
43
+
44
+ try container. encode ( clientDataJSON. base64URLEncodedString ( ) , forKey: . clientDataJSON)
45
+ try container. encode ( attestationObject. base64URLEncodedString ( ) , forKey: . attestationObject)
46
+ }
40
47
41
48
private enum CodingKeys : String , CodingKey {
42
49
case clientDataJSON
Original file line number Diff line number Diff line change @@ -43,23 +43,25 @@ public struct RegistrationCredential {
43
43
}
44
44
}
45
45
46
- extension RegistrationCredential : Decodable {
46
+ extension RegistrationCredential : Codable {
47
47
public init ( from decoder: Decoder ) throws {
48
48
let container = try decoder. container ( keyedBy: CodingKeys . self)
49
49
50
50
id = try container. decode ( URLEncodedBase64 . self, forKey: . id)
51
51
type = try container. decode ( CredentialType . self, forKey: . type)
52
- guard let rawID = try container. decode ( URLEncodedBase64 . self, forKey: . rawID) . decodedBytes else {
53
- throw DecodingError . dataCorruptedError (
54
- forKey: . rawID,
55
- in: container,
56
- debugDescription: " Failed to decode base64url encoded rawID into bytes "
57
- )
58
- }
59
- self . rawID = rawID
52
+ rawID = try container. decodeBytesFromURLEncodedBase64 ( forKey: . rawID)
60
53
attestationResponse = try container. decode ( AuthenticatorAttestationResponse . self, forKey: . attestationResponse)
61
54
}
62
55
56
+ public func encode( to encoder: Encoder ) throws {
57
+ var container = encoder. container ( keyedBy: CodingKeys . self)
58
+
59
+ try container. encode ( id, forKey: . id)
60
+ try container. encode ( rawID. base64URLEncodedString ( ) , forKey: . rawID)
61
+ try container. encode ( type, forKey: . type)
62
+ try container. encode ( attestationResponse, forKey: . attestationResponse)
63
+ }
64
+
63
65
private enum CodingKeys : String , CodingKey {
64
66
case id
65
67
case type
You can’t perform that action at this time.
0 commit comments