Skip to content

Commit 3f5f0c9

Browse files
Updated PublicKeyCredentialCreationOptions to be Codable
1 parent 4862921 commit 3f5f0c9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Sources/WebAuthn/Ceremonies/Registration/AttestationConveyancePreference.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/// Options to specify the Relying Party's preference regarding attestation conveyance during credential generation.
1616
///
1717
/// Currently only supports `none`.
18-
public enum AttestationConveyancePreference: String, Encodable, Sendable {
18+
public enum AttestationConveyancePreference: String, Codable, Sendable {
1919
/// Indicates the Relying Party is not interested in authenticator attestation.
2020
case none
2121
// case indirect

Sources/WebAuthn/Ceremonies/Registration/PublicKeyCredentialCreationOptions.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Foundation
2020
/// `Encodable` byte arrays are base64url encoded.
2121
///
2222
/// - SeeAlso: https://www.w3.org/TR/webauthn-2/#dictionary-makecredentialoptions
23-
public struct PublicKeyCredentialCreationOptions: Encodable, Sendable {
23+
public struct PublicKeyCredentialCreationOptions: Sendable {
2424
/// A byte array randomly generated by the Relying Party. Should be at least 16 bytes long to ensure sufficient
2525
/// entropy.
2626
///
@@ -47,6 +47,19 @@ public struct PublicKeyCredentialCreationOptions: Encodable, Sendable {
4747
/// Sets the Relying Party's preference for attestation conveyance. At the time of writing only `none` is
4848
/// supported.
4949
public let attestation: AttestationConveyancePreference
50+
}
51+
52+
extension PublicKeyCredentialCreationOptions: Codable {
53+
public init(from decoder: Decoder) throws {
54+
let container = try decoder.container(keyedBy: CodingKeys.self)
55+
56+
challenge = try container.decodeBytesFromURLEncodedBase64(forKey: .challenge)
57+
user = try container.decode(PublicKeyCredentialUserEntity.self, forKey: .user)
58+
relyingParty = try container.decode(PublicKeyCredentialRelyingPartyEntity.self, forKey: .relyingParty)
59+
publicKeyCredentialParameters = try container.decode([PublicKeyCredentialParameters].self, forKey: .publicKeyCredentialParameters)
60+
timeout = try container.decodeIfPresent(UInt32.self, forKey: .timeout).map { .milliseconds($0) }
61+
attestation = try container.decode(AttestationConveyancePreference.self, forKey: .attestation)
62+
}
5063

5164
public func encode(to encoder: Encoder) throws {
5265
var container = encoder.container(keyedBy: CodingKeys.self)

0 commit comments

Comments
 (0)