swift impl

This commit is contained in:
Hailey
2024-04-15 00:37:12 -07:00
parent 2ada0cbd0d
commit 2c1b3709af
7 changed files with 62 additions and 28 deletions
@@ -27,7 +27,7 @@ struct JWK : Record {
return Field(wrappedValue: self)
}
func toSecKey() throws -> SecKey? {
func toPrivateSecKey() throws -> SecKey? {
let jsonData = try JSONSerialization.data(withJSONObject: self.toDictionary())
guard let jwk = try? JSONDecoder().decode(ECPrivateKey.self, from: jsonData),
let key = try? jwk.converted(to: SecKey.self)
@@ -37,6 +37,17 @@ struct JWK : Record {
}
return key
}
func toPublicSecKey() throws -> SecKey? {
let jsonData = try JSONSerialization.data(withJSONObject: self.toDictionary())
guard let jwk = try? JSONDecoder().decode(ECPublicKey.self, from: jsonData),
let key = try? jwk.converted(to: SecKey.self)
else {
print("Error creating SecKey.")
return nil
}
return key
}
}
struct JWKPair : Record {