3 #import <Foundation/Foundation.h>
4 #import "keychain/ckks/CKKSPeer.h"
5 #import "keychain/ckks/CKKSCurrentKeyPointer.h"
7 NS_ASSUME_NONNULL_BEGIN
9 @protocol CKKSPeerUpdateListener
;
10 @
class CKKSPeerProviderState
;
12 #pragma mark - CKKSPeerProvider protocol
13 @protocol CKKSPeerProvider
<NSObject
>
14 @
property (readonly
) NSString
* providerID
;
15 @property BOOL essential
;
17 - (CKKSSelves
* _Nullable
)fetchSelfPeers
:(NSError
* _Nullable __autoreleasing
* _Nullable
)error
;
18 - (NSSet
<id
<CKKSRemotePeerProtocol
>>* _Nullable
)fetchTrustedPeers
:(NSError
* _Nullable __autoreleasing
* _Nullable
)error
;
19 // Trusted peers should include self peers
21 - (void)registerForPeerChangeUpdates
:(id
<CKKSPeerUpdateListener
>)listener
;
22 - (void)sendSelfPeerChangedUpdate
;
23 - (void)sendTrustedPeerSetChangedUpdate
;
25 - (CKKSPeerProviderState
*)currentState
;
28 #pragma mark - CKKSPeerUpdateListener protocol
29 // A CKKSPeerUpdateListener wants to be notified when a CKKSPeerProvider has new information
30 @protocol CKKSPeerUpdateListener
<NSObject
>
31 - (void)selfPeerChanged
:(id
<CKKSPeerProvider
> _Nullable
)provider
;
32 - (void)trustedPeerSetChanged
:(id
<CKKSPeerProvider
> _Nullable
)provider
;
36 #pragma mark - CKKSPeerProviderState
39 @
class CKKSTLKShareRecord
;
41 @interface CKKSPeerProviderState
: NSObject
42 @property NSString
* peerProviderID
;
44 // The peer provider believes trust in this state is essential. Any subsystem using
45 // a peer provider state should fail and pause if this is YES and there are trust errors.
46 @property BOOL essential
;
48 @
property (nonatomic
, readonly
, nullable
) CKKSSelves
* currentSelfPeers
;
49 @
property (nonatomic
, readonly
, nullable
) NSError
* currentSelfPeersError
;
50 @
property (nonatomic
, readonly
, nullable
) NSSet
<id
<CKKSRemotePeerProtocol
>>* currentTrustedPeers
;
51 @
property (nonatomic
, readonly
, nullable
) NSSet
<NSString
*>* currentTrustedPeerIDs
;
52 @
property (nonatomic
, readonly
, nullable
) NSError
* currentTrustedPeersError
;
54 - (instancetype
)initWithPeerProviderID
:(NSString
*)providerID
55 essential
:(BOOL
)essential
56 selfPeers
:(CKKSSelves
* _Nullable
)selfPeers
57 selfPeersError
:(NSError
* _Nullable
)selfPeersError
58 trustedPeers
:(NSSet
<id
<CKKSPeer
>>* _Nullable
)currentTrustedPeers
59 trustedPeersError
:(NSError
* _Nullable
)trustedPeersError
;
61 - (NSSet
<id
<CKKSPeer
>>* _Nullable
)findPeersMissingTLKSharesFor
:(CKKSCurrentKeySet
*)keyset
62 error
:(NSError
**)error
;
64 - (BOOL
)unwrapKey
:(CKKSKey
*)proposedTLK
65 fromShares
:(NSArray
<CKKSTLKShareRecord
*>*)tlkShares
66 error
:(NSError
**)error
;
68 + (CKKSPeerProviderState
*)noPeersState
:(id
<CKKSPeerProvider
>)provider
;
70 // Intended for use in PeerProviders. Thread-safety is up to the PeerProvider.
71 + (CKKSPeerProviderState
*)createFromProvider
:(id
<CKKSPeerProvider
>)provider
;