]> git.saurik.com Git - apple/security.git/blob - KeychainCircle/KCAccountKCCircleDelegate.m
Security-58286.260.20.tar.gz
[apple/security.git] / KeychainCircle / KCAccountKCCircleDelegate.m
1 //
2 // KCAccountKCCircleDelegate.m
3 // Security
4 //
5 // Created by Mitch Adler on 4/11/16.
6 //
7 //
8
9 #import <KeychainCircle/KCAccountKCCircleDelegate.h>
10
11 #include <Security/SecureObjectSync/SOSCloudCircle.h>
12
13
14 @implementation KCJoiningRequestAccountCircleDelegate
15 /*!
16 Get this devices peer info (As Application)
17
18 @result
19 SOSPeerInfoRef object or NULL if we had an error.
20 */
21 - (SOSPeerInfoRef) copyPeerInfoError: (NSError**) error {
22 CFErrorRef failure = NULL;
23 SOSPeerInfoRef result = SOSCCCopyApplication(error ? &failure : NULL);
24 if (failure != NULL && error != nil) {
25 *error = (__bridge_transfer NSError*) failure;
26 }
27 return result;
28 }
29
30 /*!
31 Handle recipt of confirmed circleJoinData over the channel
32
33 @parameter circleJoinData
34 Data the acceptor made to allow us to join the circle.
35
36 */
37 - (bool) processCircleJoinData: (NSData*) circleJoinData version:(PiggyBackProtocolVersion) version error: (NSError**)error {
38 CFErrorRef failure = NULL;
39 bool result = SOSCCJoinWithCircleJoiningBlob((__bridge CFDataRef) circleJoinData, version, &failure);
40 if (failure != NULL && error != nil) {
41 *error = (__bridge_transfer NSError*) failure;
42 }
43 return result;
44 }
45
46 + (instancetype) delegate {
47 return [[KCJoiningRequestAccountCircleDelegate alloc] init];
48 }
49
50 @end
51
52 @implementation KCJoiningAcceptAccountCircleDelegate
53 /*!
54 Handle the request's peer info and get the blob they can use to get in circle
55 @param peer
56 SOSPeerInfo sent from requestor to apply to the circle
57 @param error
58 Error resulting in looking at peer and trying to produce circle join data
59 @result
60 Data containing blob the requestor can use to get in circle
61 */
62 - (NSData*) circleJoinDataFor: (SOSPeerInfoRef) peer
63 error: (NSError**) error {
64 CFErrorRef failure = NULL;
65 CFDataRef result = SOSCCCopyCircleJoiningBlob(peer, &failure);
66 if (failure != NULL && error != nil) {
67 *error = (__bridge_transfer NSError*) failure;
68 }
69 return (__bridge_transfer NSData*) result;
70 }
71
72 -(NSData*) circleGetInitialSyncViews: (NSError**) error{
73 CFErrorRef failure = NULL;
74 CFDataRef result = SOSCCCopyInitialSyncData(&failure);
75 if (failure != NULL && error != nil) {
76 *error = (__bridge_transfer NSError*) failure;
77 }
78 return (__bridge_transfer NSData*) result;
79 }
80
81 + (instancetype) delegate {
82 return [[KCJoiningAcceptAccountCircleDelegate alloc] init];
83 }
84
85 @end
86