]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/SecureObjectSync/CKDSimulatedStore.m
Security-57740.51.3.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / SecureObjectSync / CKDSimulatedStore.m
1 //
2 // CKDSimulatedStore.m
3 // Security
4 //
5
6 #import "CKDSimulatedStore.h"
7 #import "CKDKVSProxy.h"
8
9 #include "SOSCloudKeychainConstants.h"
10 #include <utilities/debugging.h>
11
12 #import "SyncedDefaults/SYDConstants.h"
13 #include <os/activity.h>
14
15 @interface CKDSimulatedStore ()
16 @property (readwrite, weak) UbiqitousKVSProxy* proxy;
17 @property (readwrite) NSMutableDictionary<NSString*, NSObject*>* data;
18 @end
19
20 @implementation CKDSimulatedStore
21
22 + (instancetype)simulatedInterface {
23 return [[CKDSimulatedStore alloc] init];
24 }
25
26 - (instancetype)init {
27 self = [super init];
28
29 self.proxy = nil;
30 self.data = [NSMutableDictionary<NSString*, NSObject*> dictionary];
31
32 return self;
33 }
34
35 - (void) connectToProxy: (UbiqitousKVSProxy*) proxy {
36 _proxy = proxy;
37 }
38
39 - (void)setObject:(id)obj forKey:(NSString*)key {
40 [self.data setValue: obj forKey: key];
41 }
42
43 - (NSDictionary<NSString *, id>*) copyAsDictionary {
44 return self.data;
45 }
46
47 - (void)addEntriesFromDictionary:(NSDictionary<NSString*, NSObject*> *)otherDictionary {
48 [otherDictionary enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSObject * _Nonnull obj, BOOL * _Nonnull stop) {
49 [self setObject:obj forKey:key];
50 }];
51 }
52
53 - (id)objectForKey:(NSString*)key {
54 return [self.data objectForKey:key];
55 }
56
57 - (void)removeObjectForKey:(NSString*)key {
58 return [self.data removeObjectForKey:key];
59 }
60
61 - (void)removeAllObjects {
62 [self.data removeAllObjects];
63 }
64
65 - (void)pushWrites {
66 }
67
68 - (BOOL) pullUpdates:(NSError **)failure
69 {
70 return true;
71 }
72
73 - (void)remoteSetObject:(id)obj forKey:(NSString*)key
74 {
75 [self.data setObject:obj forKey:key];
76
77 if (self.proxy) {
78 [self.proxy storeKeysChanged: [NSSet setWithObject:key] initial: NO];
79 }
80 }
81
82 @end