Skip to content

Commit 6ff1b6c

Browse files
Replaced uses of AuthenticatorData Data with [UInt8] (#59)
1 parent 7203197 commit 6ff1b6c

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

Sources/WebAuthn/Ceremonies/Authentication/AuthenticatorAssertionResponse.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ extension AuthenticatorAssertionResponse: Decodable {
7070
}
7171

7272
struct ParsedAuthenticatorAssertionResponse {
73-
let rawClientData: Data
73+
let rawClientData: [UInt8]
7474
let clientData: CollectedClientData
75-
let rawAuthenticatorData: Data
75+
let rawAuthenticatorData: [UInt8]
7676
let authenticatorData: AuthenticatorData
7777
let signature: URLEncodedBase64
7878
let userHandle: [UInt8]?
7979

8080
init(from authenticatorAssertionResponse: AuthenticatorAssertionResponse) throws {
81-
rawClientData = Data(authenticatorAssertionResponse.clientDataJSON)
82-
clientData = try JSONDecoder().decode(CollectedClientData.self, from: rawClientData)
81+
rawClientData = authenticatorAssertionResponse.clientDataJSON
82+
clientData = try JSONDecoder().decode(CollectedClientData.self, from: Data(rawClientData))
8383

84-
rawAuthenticatorData = Data(authenticatorAssertionResponse.authenticatorData)
84+
rawAuthenticatorData = authenticatorAssertionResponse.authenticatorData
8585
authenticatorData = try AuthenticatorData(bytes: rawAuthenticatorData)
8686
signature = authenticatorAssertionResponse.signature.base64URLEncodedString()
8787
userHandle = authenticatorAssertionResponse.userHandle

Sources/WebAuthn/Ceremonies/Registration/AttestationObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import SwiftCBOR
1919
/// Contains the cryptographic attestation that a new key pair was created by that authenticator.
2020
public struct AttestationObject {
2121
let authenticatorData: AuthenticatorData
22-
let rawAuthenticatorData: Data
22+
let rawAuthenticatorData: [UInt8]
2323
let format: AttestationFormat
2424
let attestationStatement: CBOR
2525

Sources/WebAuthn/Ceremonies/Registration/AuthenticatorAttestationResponse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ struct ParsedAuthenticatorAttestationResponse {
7575
}
7676

7777
attestationObject = AttestationObject(
78-
authenticatorData: try AuthenticatorData(bytes: Data(authDataBytes)),
79-
rawAuthenticatorData: Data(authDataBytes),
78+
authenticatorData: try AuthenticatorData(bytes: authDataBytes),
79+
rawAuthenticatorData: authDataBytes,
8080
format: attestationFormat,
8181
attestationStatement: attestationStatement
8282
)

Sources/WebAuthn/Ceremonies/Shared/AuthenticatorData.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct AuthenticatorData: Equatable {
2828
}
2929

3030
extension AuthenticatorData {
31-
init(bytes: Data) throws {
31+
init(bytes: [UInt8]) throws {
3232
let minAuthDataLength = 37
3333
guard bytes.count >= minAuthDataLength else {
3434
throw WebAuthnError.authDataTooShort
@@ -82,7 +82,7 @@ extension AuthenticatorData {
8282
///
8383
/// This is assumed to take place after the first 37 bytes of `data`, which is always of fixed size.
8484
/// - SeeAlso: [WebAuthn Level 3 Editor's Draft §6.5.1. Attested Credential Data]( https://w3c.github.io/webauthn/#sctn-attested-credential-data)
85-
private static func parseAttestedData(_ data: Data) throws -> (AttestedCredentialData, Int) {
85+
private static func parseAttestedData(_ data: [UInt8]) throws -> (AttestedCredentialData, Int) {
8686
/// **aaguid** (16): The AAGUID of the authenticator.
8787
let aaguidLength = 16
8888
let aaguid = data[37..<(37 + aaguidLength)] // To byte at index 52
@@ -126,8 +126,8 @@ extension AuthenticatorData {
126126
class ByteInputStream: CBORInputStream {
127127
private var slice : ArraySlice<UInt8>
128128

129-
init(_ slice: Data) {
130-
self.slice = Array(slice)[...]
129+
init(_ slice: ArraySlice<UInt8>) {
130+
self.slice = slice
131131
}
132132

133133
/// The remaining bytes in the original data buffer.

Sources/WebAuthn/Ceremonies/Shared/CredentialPublicKey.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SwiftCBOR
2020
protocol PublicKey {
2121
var algorithm: COSEAlgorithmIdentifier { get }
2222
/// Verify a signature was signed with the private key corresponding to the public key.
23-
func verify(signature: Data, data: Data) throws
23+
func verify(signature: some DataProtocol, data: some DataProtocol) throws
2424
}
2525

2626
enum CredentialPublicKey {
@@ -86,7 +86,7 @@ enum CredentialPublicKey {
8686
}
8787

8888
/// Verify a signature was signed with the private key corresponding to the provided public key.
89-
func verify(signature: Data, data: Data) throws {
89+
func verify(signature: some DataProtocol, data: some DataProtocol) throws {
9090
try key.verify(signature: signature, data: data)
9191
}
9292
}
@@ -134,7 +134,7 @@ struct EC2PublicKey: PublicKey {
134134
yCoordinate = Data(yCoordinateBytes)
135135
}
136136

137-
func verify(signature: Data, data: Data) throws {
137+
func verify(signature: some DataProtocol, data: some DataProtocol) throws {
138138
switch algorithm {
139139
case .algES256:
140140
let ecdsaSignature = try P256.Signing.ECDSASignature(derRepresentation: signature)
@@ -184,7 +184,7 @@ struct RSAPublicKeyData: PublicKey {
184184
e = Data(eBytes)
185185
}
186186

187-
func verify(signature: Data, data: Data) throws {
187+
func verify(signature: some DataProtocol, data: some DataProtocol) throws {
188188
throw WebAuthnError.unsupported
189189
// let rsaSignature = _RSA.Signing.RSASignature(derRepresentation: signature)
190190

@@ -229,7 +229,7 @@ struct OKPPublicKey: PublicKey {
229229
xCoordinate = xCoordinateBytes
230230
}
231231

232-
func verify(signature: Data, data: Data) throws {
232+
func verify(signature: some DataProtocol, data: some DataProtocol) throws {
233233
throw WebAuthnError.unsupported
234234
}
235235
}

0 commit comments

Comments
 (0)