Skip to content

Commit ea34e76

Browse files
Updated PublicKeyCredentialParameters to be Codable
1 parent e6bd5b4 commit ea34e76

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Sources/WebAuthn/Ceremonies/Registration/PublicKeyCredentialCreationOptions.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public struct PublicKeyCredentialCreationOptions: Encodable, Sendable {
7171

7272
// MARK: - Credential parameters
7373
/// From §5.3 (https://w3c.github.io/TR/webauthn/#dictionary-credential-params)
74-
public struct PublicKeyCredentialParameters: Hashable, Encodable, Sendable {
74+
public struct PublicKeyCredentialParameters: Hashable, Codable, Sendable {
7575
/// The type of credential to be created. At the time of writing always ``CredentialType/publicKey``.
7676
public let type: CredentialType
7777
/// The cryptographic signature algorithm with which the newly generated credential will be used, and thus also
@@ -111,7 +111,7 @@ extension Set where Element == PublicKeyCredentialParameters {
111111
/// From §5.4.2 (https://www.w3.org/TR/webauthn/#sctn-rp-credential-params).
112112
/// The PublicKeyCredentialRelyingPartyEntity dictionary is used to supply additional Relying Party attributes when
113113
/// creating a new credential.
114-
public struct PublicKeyCredentialRelyingPartyEntity: Identifiable, Encodable, Sendable {
114+
public struct PublicKeyCredentialRelyingPartyEntity: Identifiable, Codable, Sendable {
115115
/// A unique identifier for the Relying Party entity.
116116
public let id: String
117117

@@ -126,7 +126,7 @@ public struct PublicKeyCredentialRelyingPartyEntity: Identifiable, Encodable, Se
126126
/// creating a new credential.
127127
///
128128
/// When encoding using `Encodable`, `id` is base64url encoded.
129-
public struct PublicKeyCredentialUserEntity: Identifiable, Encodable, Sendable {
129+
public struct PublicKeyCredentialUserEntity: Identifiable, Codable, Sendable {
130130
/// Generated by the Relying Party, unique to the user account, and must not contain personally identifying
131131
/// information about the user.
132132
///
@@ -150,6 +150,14 @@ public struct PublicKeyCredentialUserEntity: Identifiable, Encodable, Sendable {
150150
self.displayName = displayName
151151
}
152152

153+
public init(from decoder: Decoder) throws {
154+
let container = try decoder.container(keyedBy: CodingKeys.self)
155+
156+
self.id = try container.decodeBytesFromURLEncodedBase64(forKey: .id)
157+
self.name = try container.decode(String.self, forKey: .name)
158+
self.displayName = try container.decode(String.self, forKey: .displayName)
159+
}
160+
153161
public func encode(to encoder: Encoder) throws {
154162
var container = encoder.container(keyedBy: CodingKeys.self)
155163

Sources/WebAuthn/Ceremonies/Shared/COSE/COSEAlgorithmIdentifier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Crypto
1818
/// COSEAlgorithmIdentifier From §5.10.5. A number identifying a cryptographic algorithm. The algorithm
1919
/// identifiers SHOULD be values registered in the IANA COSE Algorithms registry
2020
/// [https://www.w3.org/TR/webauthn/#biblio-iana-cose-algs-reg], for instance, -7 for "ES256" and -257 for "RS256".
21-
public enum COSEAlgorithmIdentifier: Int, RawRepresentable, CaseIterable, Encodable, Sendable {
21+
public enum COSEAlgorithmIdentifier: Int, RawRepresentable, CaseIterable, Codable, Sendable {
2222
/// AlgES256 ECDSA with SHA-256
2323
case algES256 = -7
2424
/// AlgES384 ECDSA with SHA-384

0 commit comments

Comments
 (0)