1 #import <TargetConditionals.h>
2 #import <Foundation/Foundation.h>
5 #import "keychain/categories/NSError+UsefulConstructors.h"
7 #import "OTPairingPacketContext.h"
8 #import "OTPairingConstants.h"
10 @interface OTPairingPacketContext ()
11 @property (readwrite) NSDictionary *message;
12 @property (readwrite) NSString *fromID;
13 @property (readwrite) IDSMessageContext *context;
16 @implementation OTPairingPacketContext
18 @synthesize message = _message;
19 @synthesize fromID = _fromID;
20 @synthesize context = _context;
21 @synthesize error = _error;
23 - (instancetype)initWithMessage:(NSDictionary *)message fromID:(NSString *)fromID context:(IDSMessageContext *)context
25 if ((self = [super init])) {
26 self.message = message;
28 self.context = context;
33 - (enum OTPairingIDSMessageType)messageType
36 enum OTPairingIDSMessageType type;
38 typeNum = self.message[OTPairingIDSKeyMessageType];
40 type = [typeNum intValue];
42 // From older internal builds; remove soon
43 if (self.packetData != nil) {
44 type = OTPairingIDSMessageTypePacket;
46 type = OTPairingIDSMessageTypeError;
53 - (NSString *)sessionIdentifier
55 return self.message[OTPairingIDSKeySession];
58 - (NSData *)packetData
60 return self.message[OTPairingIDSKeyPacket];
65 if (self.messageType != OTPairingIDSMessageTypeError) {
70 NSString *errorString = self.message[OTPairingIDSKeyErrorDescription];
71 self->_error = [NSError errorWithDomain:OTPairingErrorDomain code:OTPairingErrorTypeRemote description:errorString];
77 - (NSString *)incomingResponseIdentifier
79 return self.context.incomingResponseIdentifier;
82 - (NSString *)outgoingResponseIdentifier
84 return self.context.outgoingResponseIdentifier;