7 #import <Foundation/Foundation.h>
9 // Initial messages are versioned and not typed for negotiation.
10 NS_ASSUME_NONNULL_BEGIN
12 NSData
* extractStartFromInitialMessage(NSData
* initialMessage
, uint64_t* version
, NSString
* _Nullable
* _Nullable uuidString
, NSData
* _Nullable
* _Nullable octagon
, NSError
** error
);
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
);
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
);
25 uint8_t* encode_initialmessage_version2(NSData
* data
, NSData
* uuidData
, NSData
* octagon_version
, NSError
**error
,
26 const uint8_t *der
, uint8_t *der_end
);
28 const uint8_t* _Nullable
decode_initialmessage(NSData
* _Nonnull
* _Nonnull data
, NSError
** error
,
29 const uint8_t* der
, const uint8_t *der_end
);
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
);
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
);
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
,
43 const uint8_t* der
, const uint8_t *der_end
);
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
,
50 const uint8_t* der
, const uint8_t *der_end
);
52 @interface
NSData(KCJoiningMessages
)
54 + (nullable instancetype
) dataWithEncodedString
: (NSString
*) string
55 error
: (NSError
**) error
;
57 + (nullable instancetype
) dataWithEncodedSequenceData
: (NSData
*) data1
59 error
: (NSError
**) error
;
61 - (bool) decodeSequenceData
: (NSData
* _Nullable
* _Nonnull
) data1
62 data
: (NSData
* _Nullable
* _Nonnull
) data2
63 error
: (NSError
** _Nullable
) error
;
66 + (nullable instancetype
) dataWithEncodedSequenceString
: (NSString
*) string
68 error
: (NSError
**) error
;
70 - (bool) decodeSequenceString
: (NSString
* _Nullable
* _Nonnull
) string
71 data
: (NSData
* _Nullable
* _Nonnull
) data
72 error
: (NSError
** _Nullable
) error
;
75 @interface
NSString(KCJoiningMessages
)
76 + (nullable instancetype
) decodeFromDER
: (NSData
*)der error
: (NSError
** _Nullable
) error
;
79 // Subsequent messages have a message type
91 kLargestMessageType
= kUnknown
,
93 } KCJoiningMessageType
;
96 @interface KCJoiningMessage
: NSObject
98 @
property (readonly
) KCJoiningMessageType type
;
99 @
property (readonly
) NSData
* firstData
;
100 @
property (nullable
, readonly
) NSData
* secondData
;
101 @
property (readonly
) NSData
* der
;
103 + (nullable instancetype
) messageWithDER
: (NSData
*) message
104 error
: (NSError
**) error
;
106 + (nullable instancetype
) messageWithType
: (KCJoiningMessageType
) type
107 data
: (NSData
*) firstData
108 error
: (NSError
**) error
;
110 + (nullable instancetype
) messageWithType
: (KCJoiningMessageType
) type
111 data
: (NSData
*) firstData
112 payload
: (NSData
*) secondData
113 error
: (NSError
**) error
;
116 - (nullable instancetype
) initWithDER
: (NSData
*) message
117 error
: (NSError
**) error NS_DESIGNATED_INITIALIZER
;
119 - (nullable instancetype
) initWithType
: (KCJoiningMessageType
) type
120 data
: (NSData
*) firstData
121 payload
: (nullable NSData
*) secondData
122 error
: (NSError
**) error NS_DESIGNATED_INITIALIZER
;
125 - (instancetype
) init NS_UNAVAILABLE
;
129 NS_ASSUME_NONNULL_END