@@ -19,7 +19,7 @@ import Foundation
19
19
/// When encoding using `Encodable`, the byte arrays are encoded as base64url.
20
20
///
21
21
/// - SeeAlso: https://www.w3.org/TR/webauthn-2/#dictionary-assertion-options
22
- public struct PublicKeyCredentialRequestOptions : Encodable , Sendable {
22
+ public struct PublicKeyCredentialRequestOptions : Sendable {
23
23
/// A challenge that the authenticator signs, along with other data, when producing an authentication assertion
24
24
///
25
25
/// When encoding using `Encodable` this is encoded as base64url.
@@ -45,7 +45,19 @@ public struct PublicKeyCredentialRequestOptions: Encodable, Sendable {
45
45
public let userVerification : UserVerificationRequirement ?
46
46
47
47
// let extensions: [String: Any]
48
+ }
48
49
50
+ extension PublicKeyCredentialRequestOptions : Codable {
51
+ public init ( from decoder: Decoder ) throws {
52
+ let container = try decoder. container ( keyedBy: CodingKeys . self)
53
+
54
+ challenge = try container. decodeBytesFromURLEncodedBase64 ( forKey: . challenge)
55
+ timeout = try container. decodeIfPresent ( UInt32 . self, forKey: . timeout) . map { . milliseconds( $0) }
56
+ relyingPartyID = try container. decode ( String . self, forKey: . rpID)
57
+ allowCredentials = try container. decodeIfPresent ( [ PublicKeyCredentialDescriptor ] . self, forKey: . allowCredentials)
58
+ userVerification = try container. decodeIfPresent ( UserVerificationRequirement . self, forKey: . userVerification)
59
+ }
60
+
49
61
public func encode( to encoder: Encoder ) throws {
50
62
var container = encoder. container ( keyedBy: CodingKeys . self)
51
63
@@ -68,10 +80,10 @@ public struct PublicKeyCredentialRequestOptions: Encodable, Sendable {
68
80
/// Information about a generated credential.
69
81
///
70
82
/// When encoding using `Encodable`, `id` is encoded as base64url.
71
- public struct PublicKeyCredentialDescriptor : Equatable , Encodable , Sendable {
83
+ public struct PublicKeyCredentialDescriptor : Equatable , Codable , Sendable {
72
84
/// Defines hints as to how clients might communicate with a particular authenticator in order to obtain an
73
85
/// assertion for a specific credential
74
- public enum AuthenticatorTransport : String , Equatable , Encodable , Sendable {
86
+ public enum AuthenticatorTransport : String , Equatable , Codable , Sendable {
75
87
/// Indicates the respective authenticator can be contacted over removable USB.
76
88
case usb
77
89
/// Indicates the respective authenticator can be contacted over Near Field Communication (NFC).
@@ -107,6 +119,14 @@ public struct PublicKeyCredentialDescriptor: Equatable, Encodable, Sendable {
107
119
self . id = id
108
120
self . transports = transports
109
121
}
122
+
123
+ public init ( from decoder: Decoder ) throws {
124
+ let container = try decoder. container ( keyedBy: CodingKeys . self)
125
+
126
+ type = try container. decode ( CredentialType . self, forKey: . type)
127
+ id = try container. decodeBytesFromURLEncodedBase64 ( forKey: . id)
128
+ transports = try container. decode ( [ AuthenticatorTransport ] . self, forKey: . transports)
129
+ }
110
130
111
131
public func encode( to encoder: Encoder ) throws {
112
132
var container = encoder. container ( keyedBy: CodingKeys . self)
@@ -125,7 +145,7 @@ public struct PublicKeyCredentialDescriptor: Equatable, Encodable, Sendable {
125
145
126
146
/// The Relying Party may require user verification for some of its operations but not for others, and may use this
127
147
/// type to express its needs.
128
- public enum UserVerificationRequirement : String , Encodable , Sendable {
148
+ public enum UserVerificationRequirement : String , Codable , Sendable {
129
149
/// The Relying Party requires user verification for the operation and will fail the overall ceremony if the
130
150
/// user wasn't verified.
131
151
case required
0 commit comments