-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathX25519Key.swift
59 lines (51 loc) · 1.99 KB
/
X25519Key.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import CryptoKit
import Domain
import Foundation
struct X25519PrivateKey: PrivateKey {
private let appleCurve: Curve25519.KeyAgreement.PrivateKey
let keyType: String = "EC"
let keySpecifications: [String : String] = [
"curve" : "x25519"
]
var size: Int { raw.count }
var raw: Data { appleCurve.rawRepresentation }
init(appleCurve: Curve25519.KeyAgreement.PrivateKey) {
self.appleCurve = appleCurve
}
func publicKey() -> PublicKey {
X25519PublicKey(appleCurve: appleCurve.publicKey)
}
}
extension X25519PrivateKey: KeychainStorableKey {
var restorationIdentifier: String { "x25519+priv" }
var storableData: Data { raw }
var index: Int? { nil }
var type: Domain.KeychainStorableKeyProperties.KeyAlgorithm { .rawKey }
var keyClass: Domain.KeychainStorableKeyProperties.KeyType { .privateKey }
var accessiblity: Domain.KeychainStorableKeyProperties.Accessability? { .firstUnlock(deviceOnly: true) }
var synchronizable: Bool { false }
}
struct X25519PublicKey: PublicKey {
private let appleCurve: Curve25519.KeyAgreement.PublicKey
let keyType: String = "EC"
let keySpecifications: [String : String] = [
"curve" : "x25519"
]
var size: Int { raw.count }
var raw: Data { appleCurve.rawRepresentation }
init(appleCurve: Curve25519.KeyAgreement.PublicKey) {
self.appleCurve = appleCurve
}
func verify(data: Data, signature: Data) throws -> Bool {
throw ApolloError.keyAgreementDoesNotSupportVerification
}
}
extension X25519PublicKey: KeychainStorableKey {
var restorationIdentifier: String { "x25519+pub" }
var storableData: Data { raw }
var index: Int? { nil }
var type: Domain.KeychainStorableKeyProperties.KeyAlgorithm { .rawKey }
var keyClass: Domain.KeychainStorableKeyProperties.KeyType { .publicKey }
var accessiblity: Domain.KeychainStorableKeyProperties.Accessability? { .firstUnlock(deviceOnly: true) }
var synchronizable: Bool { false }
}