]> git.saurik.com Git - apple/security.git/blob - keychain/ot/OctagonStateMachineObservers.h
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / ot / OctagonStateMachineObservers.h
1
2 #if OCTAGON
3
4 #import <Foundation/Foundation.h>
5 #import "keychain/ckks/CKKSResultOperation.h"
6 #import "keychain/ckks/CKKSAnalytics.h"
7 #import "keychain/ot/OctagonStateMachineHelpers.h"
8
9 NS_ASSUME_NONNULL_BEGIN
10
11 @interface OctagonStateTransitionPathStep : NSObject
12 @property BOOL successState;
13 @property (readonly) NSDictionary<OctagonState*, OctagonStateTransitionPathStep*>* followStates;
14
15 - (instancetype)initAsSuccess;
16 - (instancetype)initWithPath:(NSDictionary<OctagonState*, OctagonStateTransitionPathStep*>*)followStates;
17
18 - (BOOL)successState;
19
20 + (OctagonStateTransitionPathStep*)success;
21
22 // Dict should be a map of states to either:
23 // 1. A dictionary matching this specifiction
24 // 2. an OctagonStateTransitionPathStep object (which is likely a success object, but doesn't have to be)
25 // Any other object will be ignored. A malformed dictionary will be converted into an empty success path.
26 + (OctagonStateTransitionPathStep*)pathFromDictionary:(NSDictionary<OctagonState*, id>*)pathDict;
27 @end
28
29
30 @interface OctagonStateTransitionPath : NSObject
31 @property OctagonState* initialState;
32 @property OctagonStateTransitionPathStep* pathStep;
33
34 - (instancetype)initWithState:(OctagonState*)initialState
35 pathStep:(OctagonStateTransitionPathStep*)pathSteps;
36
37 - (OctagonStateTransitionPathStep*)asPathStep;
38
39 // Uses the same rules as OctagonStateTransitionPathStep pathFromDictionary, but selects one of the top-level dictionary keys
40 // to be the path initialization state. Not well defined if you pass in two keys in the top-level dictionary.
41 // If the dictionary has no keys in it, returns nil.
42 + (OctagonStateTransitionPath* _Nullable)pathFromDictionary:(NSDictionary<OctagonState*, id>*)pathDict;
43
44 @end
45
46
47
48 @protocol OctagonStateTransitionWatcherProtocol
49 @property (readonly) CKKSResultOperation* result;
50 - (void)onqueueHandleTransition:(CKKSResultOperation<OctagonStateTransitionOperationProtocol>*)attempt;
51 @end
52
53 @interface OctagonStateTransitionWatcher : NSObject <OctagonStateTransitionWatcherProtocol>
54 @property (readonly) NSString* name;
55 @property (readonly) CKKSResultOperation* result;
56 @property (readonly) OctagonStateTransitionPath* intendedPath;
57
58 // If the initial request times out, the watcher will fail as well.
59 - (instancetype)initNamed:(NSString*)name
60 serialQueue:(dispatch_queue_t)queue
61 path:(OctagonStateTransitionPath*)path
62 initialRequest:(OctagonStateTransitionRequest* _Nullable)initialRequest;
63
64 - (instancetype)timeout:(dispatch_time_t)timeout;
65
66 @end
67
68 // Reports on if any of the given states are entered
69 @interface OctagonStateMultiStateArrivalWatcher : NSObject <OctagonStateTransitionWatcherProtocol>
70 @property (readonly) NSString* name;
71 @property (readonly) CKKSResultOperation* result;
72 @property (readonly) NSSet<OctagonState*>* states;
73
74 - (instancetype)initNamed:(NSString*)name
75 serialQueue:(dispatch_queue_t)queue
76 states:(NSSet<OctagonState*>*)states;
77
78 // Called by the state machine if it's already in a state at registration time
79 - (void)onqueueEnterState:(OctagonState*)state;
80
81 - (instancetype)timeout:(dispatch_time_t)timeout;
82 @end
83
84 NS_ASSUME_NONNULL_END
85
86 #endif // OCTAGON