]> git.saurik.com Git - apple/security.git/blob - keychain/escrowrequest/tests/MockSynchronousEscrowServer.m
Security-59306.11.20.tar.gz
[apple/security.git] / keychain / escrowrequest / tests / MockSynchronousEscrowServer.m
1
2 #import "MockSynchronousEscrowServer.h"
3
4 @interface MockSynchronousEscrowServer ()
5 @property EscrowRequestServer* server;
6 @end
7
8 @implementation MockSynchronousEscrowServer
9
10 - (instancetype)initWithServer:(EscrowRequestServer*)server
11 {
12 if((self = [super init])) {
13 _server = server;
14 }
15 return self;
16 }
17
18 - (void)cachePrerecord:(NSString*)uuid
19 serializedPrerecord:(nonnull NSData *)prerecord
20 reply:(nonnull void (^)(NSError * _Nullable))reply
21 {
22 dispatch_semaphore_t sema = dispatch_semaphore_create(0);
23
24 [self.server cachePrerecord:uuid
25 serializedPrerecord:prerecord
26 reply:^(NSError * _Nullable error) {
27 reply(error);
28 dispatch_semaphore_signal(sema);
29 }];
30
31 dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
32 }
33
34 - (void)fetchPrerecord:(nonnull NSString *)prerecordUUID
35 reply:(nonnull void (^)(NSData * _Nullable, NSError * _Nullable))reply
36 {
37
38 dispatch_semaphore_t sema = dispatch_semaphore_create(0);
39
40 [self.server fetchPrerecord:prerecordUUID
41 reply:^(NSData* contents, NSError * _Nullable error) {
42 reply(contents, error);
43 dispatch_semaphore_signal(sema);
44 }];
45
46 dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
47 }
48
49 - (void)fetchRequestWaitingOnPasscode:(nonnull void (^)(NSString * _Nullable, NSError * _Nullable))reply
50 {
51 dispatch_semaphore_t sema = dispatch_semaphore_create(0);
52
53 [self.server fetchRequestWaitingOnPasscode:^(NSString* uuid, NSError * _Nullable error) {
54 reply(uuid, error);
55 dispatch_semaphore_signal(sema);
56 }];
57
58 dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
59 }
60
61 - (void)triggerEscrowUpdate:(nonnull NSString *)reason
62 reply:(nonnull void (^)(NSError * _Nullable))reply
63 {
64 dispatch_semaphore_t sema = dispatch_semaphore_create(0);
65
66 [self.server triggerEscrowUpdate:reason reply:^(NSError * _Nullable error) {
67 reply(error);
68 dispatch_semaphore_signal(sema);
69 }];
70
71 dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
72 }
73
74 - (void)fetchRequestStatuses:(nonnull void (^)(NSDictionary<NSString *,NSString *> * _Nullable, NSError * _Nullable))reply {
75 dispatch_semaphore_t sema = dispatch_semaphore_create(0);
76
77 [self.server fetchRequestStatuses:^(NSDictionary<NSString *,NSString *> * dict, NSError * _Nullable error) {
78 reply(dict, error);
79 dispatch_semaphore_signal(sema);
80 }];
81
82 dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
83 }
84
85 - (void)resetAllRequests:(nonnull void (^)(NSError * _Nullable))reply {
86 dispatch_semaphore_t sema = dispatch_semaphore_create(0);
87
88 [self.server resetAllRequests:^(NSError * _Nullable error) {
89 reply(error);
90 dispatch_semaphore_signal(sema);
91 }];
92
93 dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
94 }
95
96 - (void)storePrerecordsInEscrow:(nonnull void (^)(uint64_t, NSError * _Nullable))reply {
97
98 dispatch_semaphore_t sema = dispatch_semaphore_create(0);
99
100 [self.server storePrerecordsInEscrow:^(uint64_t x, NSError * _Nullable error) {
101 reply(x, error);
102 dispatch_semaphore_signal(sema);
103 }];
104
105 dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
106 }
107
108 @end