@@ -84,6 +84,8 @@ struct EC2PublicKey: PublicKey {
84
84
/// A byte string 32 bytes in length that holds the y coordinate of the key.
85
85
let yCoordinate : [ UInt8 ]
86
86
87
+ var rawRepresentation : [ UInt8 ] { xCoordinate + yCoordinate }
88
+
87
89
init ( publicKeyObject: CBOR , algorithm: COSEAlgorithmIdentifier ) throws {
88
90
self . algorithm = algorithm
89
91
@@ -108,7 +110,6 @@ struct EC2PublicKey: PublicKey {
108
110
}
109
111
110
112
func getString( ) throws -> String {
111
- let rawRepresentation = xCoordinate + yCoordinate
112
113
switch algorithm {
113
114
case . algES256:
114
115
return try P256 . Signing. PublicKey ( rawRepresentation: rawRepresentation) . pemRepresentation
@@ -122,7 +123,28 @@ struct EC2PublicKey: PublicKey {
122
123
}
123
124
124
125
func verify( signature: Data , data: Data ) throws {
125
- fatalError ( " Not implemented " )
126
+ switch algorithm {
127
+ case . algES256:
128
+ let ecdsaSignature = try P256 . Signing. ECDSASignature ( derRepresentation: signature)
129
+ guard try P256 . Signing. PublicKey ( rawRepresentation: rawRepresentation)
130
+ . isValidSignature ( ecdsaSignature, for: data) else {
131
+ throw WebAuthnError . badRequestData
132
+ }
133
+ case . algES384:
134
+ let ecdsaSignature = try P384 . Signing. ECDSASignature ( derRepresentation: signature)
135
+ guard try P384 . Signing. PublicKey ( rawRepresentation: rawRepresentation)
136
+ . isValidSignature ( ecdsaSignature, for: data) else {
137
+ throw WebAuthnError . badRequestData
138
+ }
139
+ case . algES512:
140
+ let ecdsaSignature = try P521 . Signing. ECDSASignature ( derRepresentation: signature)
141
+ guard try P521 . Signing. PublicKey ( rawRepresentation: rawRepresentation)
142
+ . isValidSignature ( ecdsaSignature, for: data) else {
143
+ throw WebAuthnError . badRequestData
144
+ }
145
+ default :
146
+ throw WebAuthnError . unsupportedCOSEAlgorithm
147
+ }
126
148
}
127
149
}
128
150
0 commit comments