]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSProvideKeySetOperation.m
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / ckks / CKKSProvideKeySetOperation.m
1
2 #if OCTAGON
3
4 #import "CKKSProvideKeySetOperation.h"
5
6 @interface CKKSProvideKeySetOperation ()
7 @property (nullable) CKKSCurrentKeySet* keyset;
8 @property dispatch_queue_t queue;
9
10 @property (nullable) NSOperation* startDependency;
11 @end
12
13 @implementation CKKSProvideKeySetOperation
14 @synthesize zoneName = _zoneName;
15 @synthesize keyset = _keyset;
16
17 - (instancetype)initWithZoneName:(NSString*)zoneName
18 {
19 if((self = [super init])) {
20 _zoneName = zoneName;
21 _keyset = nil;
22 _startDependency = [NSBlockOperation blockOperationWithBlock:^{}];
23 _startDependency.name = @"key-set-provided";
24
25 _queue = dispatch_queue_create("key-set-queue", DISPATCH_QUEUE_SERIAL);
26
27 [self addDependency:_startDependency];
28 }
29 return self;
30 }
31
32 - (void)provideKeySet:(CKKSCurrentKeySet *)keyset
33 {
34 // Ensure that only one keyset is provided through each operation
35 dispatch_sync(self.queue, ^{
36 if(!self.keyset) {
37 self.keyset = keyset;
38 if(self.startDependency) {
39 // Create a new queue here, just to be safe in case someone is waiting
40 NSOperationQueue* queue = [[NSOperationQueue alloc] init];
41 [queue addOperation:self.startDependency];
42 self.startDependency = nil;
43 }
44 }
45 });
46
47 }
48 @end
49
50 #endif // OCTAGON