]> git.saurik.com Git - apple/security.git/blob - KeychainCircle/KCJoiningMessages.h
Security-59754.41.1.tar.gz
[apple/security.git] / KeychainCircle / KCJoiningMessages.h
1 //
2 // KCJoiningMessages.h
3 // KeychainCircle
4 //
5 //
6
7 #import <Foundation/Foundation.h>
8
9 // Initial messages are versioned and not typed for negotiation.
10 NS_ASSUME_NONNULL_BEGIN
11
12 NSData* extractStartFromInitialMessage(NSData* initialMessage, uint64_t* version, NSString* _Nullable * _Nullable uuidString, NSData* _Nullable * _Nullable octagon, NSError** error);
13
14 size_t sizeof_initialmessage(NSData*data);
15 size_t sizeof_initialmessage_version1(NSData*data, uint64_t version1, NSData *uuid);
16 size_t sizeof_initialmessage_version2(NSData*data, uint64_t version1, NSData *uuid, NSData* octagon);
17
18
19
20 uint8_t* _Nullable encode_initialmessage(NSData* data, NSError**error,
21 const uint8_t *der, uint8_t *der_end);
22 uint8_t* _Nullable encode_initialmessage_version1(NSData* data, NSData* uuidData, uint64_t piggy_version, NSError**error,
23 const uint8_t *der, uint8_t *der_end);
24
25 uint8_t* encode_initialmessage_version2(NSData* data, NSData* uuidData, NSData* octagon_version, NSError**error,
26 const uint8_t *der, uint8_t *der_end);
27
28 const uint8_t* _Nullable decode_initialmessage(NSData* _Nonnull * _Nonnull data, NSError** error,
29 const uint8_t* der, const uint8_t *der_end);
30
31 const uint8_t* _Nullable decode_version1(NSData* _Nonnull* _Nonnull data, NSData* _Nullable* _Nullable uuid, uint64_t * _Nullable piggy_version, NSError** error,
32 const uint8_t* der, const uint8_t *der_end);
33
34 const uint8_t* _Nullable decode_version2(NSData* _Nonnull* _Nonnull data, NSData* _Nullable* _Nullable uuid, NSData* _Nullable* _Nullable octagon, uint64_t* _Nullable piggy_version, NSError** error,
35 const uint8_t* der, const uint8_t *der_end);
36
37
38 size_t sizeof_seq_data_data(NSData*data1, NSData*data2, NSError** error);
39 uint8_t* _Nullable encode_seq_data_data(NSData* data, NSData*data2, NSError**error,
40 const uint8_t *der, uint8_t *der_end);
41 const uint8_t* _Nullable decode_seq_data_data(NSData* _Nonnull * _Nonnull data1, NSData* _Nonnull * _Nonnull data2,
42 NSError** error,
43 const uint8_t* der, const uint8_t *der_end);
44
45 size_t sizeof_seq_string_data(NSString*string, NSData*data, NSError** error);
46 uint8_t* _Nullable encode_seq_string_data(NSString* string, NSData*data, NSError**error,
47 const uint8_t *der, uint8_t *der_end);
48 const uint8_t* _Nullable decode_seq_string_data(NSString* _Nonnull * _Nonnull string, NSData* _Nonnull * _Nonnull data,
49 NSError** error,
50 const uint8_t* der, const uint8_t *der_end);
51
52 @interface NSData(KCJoiningMessages)
53
54 + (nullable instancetype) dataWithEncodedString: (NSString*) string
55 error: (NSError**) error;
56
57 + (nullable instancetype) dataWithEncodedSequenceData: (NSData*) data1
58 data: (NSData*) data2
59 error: (NSError**) error;
60
61 - (bool) decodeSequenceData: (NSData* _Nullable * _Nonnull) data1
62 data: (NSData* _Nullable * _Nonnull) data2
63 error: (NSError** _Nullable) error;
64
65
66 + (nullable instancetype) dataWithEncodedSequenceString: (NSString*) string
67 data: (NSData*) data
68 error: (NSError**) error;
69
70 - (bool) decodeSequenceString: (NSString* _Nullable * _Nonnull) string
71 data: (NSData* _Nullable * _Nonnull) data
72 error: (NSError** _Nullable) error;
73 @end
74
75 @interface NSString(KCJoiningMessages)
76 + (nullable instancetype) decodeFromDER: (NSData*)der error: (NSError** _Nullable) error;
77 @end
78
79 // Subsequent messages have a message type
80 typedef enum {
81 kChallenge = 1,
82 kResponse = 2,
83 kVerification = 3,
84 kPeerInfo = 4,
85 kCircleBlob = 5,
86
87 kTLKRequest = 6,
88
89 kError = 0,
90
91 kUnknown = 255,
92
93 kLargestMessageType = kUnknown,
94
95 } KCJoiningMessageType;
96
97
98 @interface KCJoiningMessage : NSObject
99
100 @property (readonly) KCJoiningMessageType type;
101 @property (readonly) NSData* firstData;
102 @property (nullable, readonly) NSData* secondData;
103 @property (readonly) NSData* der;
104
105 + (nullable instancetype) messageWithDER: (NSData*) message
106 error: (NSError**) error;
107
108 + (nullable instancetype) messageWithType: (KCJoiningMessageType) type
109 data: (NSData*) firstData
110 error: (NSError**) error;
111
112 + (nullable instancetype) messageWithType: (KCJoiningMessageType) type
113 data: (NSData*) firstData
114 payload: (nullable NSData*) secondData
115 error: (NSError**) error;
116
117
118 - (nullable instancetype) initWithDER: (NSData*) message
119 error: (NSError**) error NS_DESIGNATED_INITIALIZER;
120
121 - (nullable instancetype) initWithType: (KCJoiningMessageType) type
122 data: (NSData*) firstData
123 payload: (nullable NSData*) secondData
124 error: (NSError**) error NS_DESIGNATED_INITIALIZER;
125
126
127 - (instancetype) init NS_UNAVAILABLE;
128
129 @end
130
131 NS_ASSUME_NONNULL_END
132