4 #import "keychain/ot/OctagonFlags.h"
5 #import "keychain/ot/OTStates.h"
6 #import "keychain/ckks/CKKSCondition.h"
8 @interface OctagonFlags ()
9 @property dispatch_queue_t queue;
10 @property NSMutableSet<OctagonFlag*>* flags;
11 @property (readonly) NSSet* allowableFlags;
14 @implementation OctagonFlags
16 - (instancetype)initWithQueue:(dispatch_queue_t)queue
17 flags:(NSSet<OctagonFlag*>*)possibleFlags
19 if((self = [super init])) {
21 _flags = [NSMutableSet set];
22 _flagConditions = [[NSMutableDictionary alloc] init];
23 _allowableFlags = possibleFlags;
25 for(OctagonFlag* flag in possibleFlags) {
26 self.flagConditions[flag] = [[CKKSCondition alloc] init];
32 - (NSString*)description
34 return [NSString stringWithFormat:@"<OctagonFlags: %@>", [self contentsAsString]];
37 - (NSString*)contentsAsString
39 if(self.flags.count == 0) {
42 return [[self.flags allObjects] componentsJoinedByString:@","];
45 - (NSArray<NSString*>*)dumpFlags
47 return [self.flags allObjects];
50 - (BOOL)_onqueueContains:(nonnull OctagonFlag *)flag {
51 dispatch_assert_queue(self.queue);
52 return [self.flags containsObject:flag];
55 - (void)_onqueueSetFlag:(nonnull OctagonFlag *)flag {
56 dispatch_assert_queue(self.queue);
57 [self.flags addObject:flag];
60 - (CKKSCondition*)conditionForFlag:(OctagonFlag*)flag {
61 return self.flagConditions[flag];
64 - (void)setFlag:(nonnull OctagonFlag *)flag {
65 dispatch_sync(self.queue, ^{
66 [self _onqueueSetFlag:flag];
70 - (void)_onqueueRemoveFlag:(nonnull OctagonFlag *)flag {
71 dispatch_assert_queue(self.queue);
73 NSAssert([self.allowableFlags containsObject:flag], @"state machine tried to handle unknown flag %@", flag);
75 [self.flags removeObject:flag];
76 [self.flagConditions[flag] fulfill];
77 self.flagConditions[flag] = [[CKKSCondition alloc]init];