Skip to content

Commit 8035e34

Browse files
authored
Improved how Strings are serialized into Data objects (#80)
1 parent 686df63 commit 8035e34

File tree

4 files changed

+3
-7
lines changed

4 files changed

+3
-7
lines changed

Sources/WebAuthn/Ceremonies/Authentication/AuthenticatorAssertionResponse.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ struct ParsedAuthenticatorAssertionResponse: Sendable {
102102
relyingPartyOrigin: relyingPartyOrigin
103103
)
104104

105-
guard let expectedRelyingPartyIDData = relyingPartyID.data(using: .utf8) else {
106-
throw WebAuthnError.invalidRelyingPartyID
107-
}
105+
let expectedRelyingPartyIDData = Data(relyingPartyID.utf8)
108106
let expectedRelyingPartyIDHash = SHA256.hash(data: expectedRelyingPartyIDData)
109107
guard expectedRelyingPartyIDHash == authenticatorData.relyingPartyIDHash else {
110108
throw WebAuthnError.relyingPartyIDHashDoesNotMatch

Sources/WebAuthn/Ceremonies/Registration/AttestationObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public struct AttestationObject: Sendable {
3030
supportedPublicKeyAlgorithms: [PublicKeyCredentialParameters],
3131
pemRootCertificatesByFormat: [AttestationFormat: [Data]] = [:]
3232
) async throws -> AttestedCredentialData {
33-
let relyingPartyIDHash = SHA256.hash(data: relyingPartyID.data(using: .utf8)!)
33+
let relyingPartyIDHash = SHA256.hash(data: Data(relyingPartyID.utf8))
3434

3535
guard relyingPartyIDHash == authenticatorData.relyingPartyIDHash else {
3636
throw WebAuthnError.relyingPartyIDHashDoesNotMatch

Sources/WebAuthn/WebAuthnError.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public struct WebAuthnError: Error, Hashable, Sendable {
3030
case invalidUserID
3131
case unsupportedCredentialPublicKeyAlgorithm
3232
case credentialIDAlreadyExists
33-
case invalidRelyingPartyID
3433
case userVerifiedFlagNotSet
3534
case potentialReplayAttack
3635
case invalidAssertionCredentialType
@@ -90,7 +89,6 @@ public struct WebAuthnError: Error, Hashable, Sendable {
9089
public static let invalidUserID = Self(reason: .invalidUserID)
9190
public static let unsupportedCredentialPublicKeyAlgorithm = Self(reason: .unsupportedCredentialPublicKeyAlgorithm)
9291
public static let credentialIDAlreadyExists = Self(reason: .credentialIDAlreadyExists)
93-
public static let invalidRelyingPartyID = Self(reason: .invalidRelyingPartyID)
9492
public static let userVerifiedFlagNotSet = Self(reason: .userVerifiedFlagNotSet)
9593
public static let potentialReplayAttack = Self(reason: .potentialReplayAttack)
9694
public static let invalidAssertionCredentialType = Self(reason: .invalidAssertionCredentialType)

Tests/WebAuthnTests/Utils/TestModels/TestAuthData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct TestAuthDataBuilder {
8787
}
8888

8989
func relyingPartyIDHash(fromRelyingPartyID relyingPartyID: String) -> Self {
90-
let relyingPartyIDData = relyingPartyID.data(using: .utf8)!
90+
let relyingPartyIDData = Data(relyingPartyID.utf8)
9191
let relyingPartyIDHash = SHA256.hash(data: relyingPartyIDData)
9292
var temp = self
9393
temp.wrapped.relyingPartyIDHash = [UInt8](relyingPartyIDHash)

0 commit comments

Comments
 (0)