]> git.saurik.com Git - apple/security.git/blob - keychain/TrustedPeersHelper/OctagonPeerKeys.swift
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / TrustedPeersHelper / OctagonPeerKeys.swift
1 import Foundation
2
3 enum OctagonSelfPeerKeysError: Error {
4 case noPublicKeys
5 }
6
7 class OctagonSelfPeerKeys: NSObject, CKKSSelfPeer {
8 var encryptionKey: _SFECKeyPair
9 var signingKey: _SFECKeyPair
10 var peerID: String
11
12 // Here for conformance with CKKSPeer
13 var publicEncryptionKey: _SFECPublicKey?
14 var publicSigningKey: _SFECPublicKey?
15
16 var encryptionVerificationKey: _SFECPublicKey
17 var signingVerificationKey: _SFECPublicKey
18
19 func matchesPeer(_ peer: CKKSPeer) -> Bool {
20 return false
21 }
22
23 init(peerID: String, signingKey: _SFECKeyPair, encryptionKey: _SFECKeyPair) throws {
24 self.peerID = peerID
25 self.signingKey = signingKey
26 self.encryptionKey = encryptionKey
27
28 self.publicEncryptionKey = encryptionKey.publicKey as? _SFECPublicKey
29 self.publicSigningKey = signingKey.publicKey as? _SFECPublicKey
30
31 guard let encryptionVerificationKey = self.publicEncryptionKey,
32 let signingVerificationKey = self.publicSigningKey else {
33 throw OctagonSelfPeerKeysError.noPublicKeys
34 }
35
36 self.encryptionVerificationKey = encryptionVerificationKey
37 self.signingVerificationKey = signingVerificationKey
38 }
39
40 override var description: String {
41 return "<OctagonSelfPeerKeys: \(self.peerID)>"
42 }
43 }
44
45 extension TPPeerPermanentInfo: CKKSPeer {
46 public var publicEncryptionKey: _SFECPublicKey? {
47 return self.encryptionPubKey as? _SFECPublicKey
48 }
49
50 public var publicSigningKey: _SFECPublicKey? {
51 return self.signingPubKey as? _SFECPublicKey
52 }
53
54 public func matchesPeer(_ peer: CKKSPeer) -> Bool {
55 return self.peerID == peer.peerID
56 }
57 }