]> git.saurik.com Git - apple/security.git/blob - keychain/ot/OctagonPendingFlag.m
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / ot / OctagonPendingFlag.m
1
2 #if OCTAGON
3
4 #import "keychain/ot/OctagonPendingFlag.h"
5
6 NSString* OctagonPendingConditionsToString(OctagonPendingConditions cond)
7 {
8 if((cond & OctagonPendingConditionsDeviceUnlocked) != 0x0) {
9 return @"unlock";
10 }
11 if(cond == 0x0) {
12 return @"none";
13 }
14 return [NSString stringWithFormat:@"Unknown conditions: 0x%x", (int)cond];
15 }
16
17 @implementation OctagonPendingFlag
18
19 - (instancetype)initWithFlag:(OctagonFlag*)flag delayInSeconds:(NSTimeInterval)delay
20 {
21 if ((self = [super init])) {
22 _flag = flag;
23 _fireTime = [NSDate dateWithTimeIntervalSinceNow:delay];
24 _afterOperation = nil;
25 _conditions = 0;
26 }
27 return self;
28 }
29
30 - (instancetype)initWithFlag:(OctagonFlag*)flag
31 conditions:(OctagonPendingConditions)conditions
32 {
33 if ((self = [super init])) {
34 _flag = flag;
35 _fireTime = nil;
36 _afterOperation = nil;
37 _conditions = conditions;
38 }
39 return self;
40 }
41
42 - (instancetype)initWithFlag:(OctagonFlag*)flag after:(NSOperation*)op
43 {
44 if ((self = [super init])) {
45 _flag = flag;
46 _fireTime = nil;
47 _afterOperation = op;
48 _conditions = 0;
49 }
50 return self;
51 }
52
53 - (NSString*)description {
54 if(self.fireTime) {
55 return [NSString stringWithFormat:@"<OctagonPendingFlag: %@: %@>", self.flag, self.fireTime];
56 } else if(self.afterOperation) {
57 return [NSString stringWithFormat:@"<OctagonPendingFlag: %@: %@>", self.flag, self.afterOperation];
58 } else {
59 return [NSString stringWithFormat:@"<OctagonPendingFlag: %@: %@>", self.flag, OctagonPendingConditionsToString(self.conditions)];
60 }
61 }
62
63 @end
64
65 #endif // OCTAGON