]> git.saurik.com Git - apple/security.git/blob - keychain/ot/OTJoiningConfiguration.m
Security-59306.41.2.tar.gz
[apple/security.git] / keychain / ot / OTJoiningConfiguration.m
1 /*
2 * Copyright (c) 2018 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #import "keychain/ot/OTJoiningConfiguration.h"
25
26 #if __OBJC2__
27
28 NS_ASSUME_NONNULL_BEGIN
29
30 @implementation OTJoiningConfiguration
31
32 + (BOOL)supportsSecureCoding {
33 return YES;
34 }
35
36 - (instancetype)initWithProtocolType:(NSString*)protocolType
37 uniqueDeviceID:(NSString*)uniqueDeviceID
38 uniqueClientID:(NSString*)uniqueClientID
39 containerName:(NSString* _Nullable)containerName
40 contextID:(NSString*)contextID
41 epoch:(uint64_t)epoch
42 isInitiator:(BOOL)isInitiator
43 {
44 return [self initWithProtocolType:protocolType
45 uniqueDeviceID:uniqueDeviceID
46 uniqueClientID:uniqueClientID
47 pairingUUID:[NSUUID UUID].UUIDString
48 containerName:containerName
49 contextID:contextID
50 epoch:(uint64_t)epoch
51 isInitiator:isInitiator];
52 }
53
54 - (instancetype)initWithProtocolType:(NSString*)protocolType
55 uniqueDeviceID:(NSString*)uniqueDeviceID
56 uniqueClientID:(NSString*)uniqueClientID
57 pairingUUID:(NSString* _Nullable)pairingUUID
58 containerName:(NSString* _Nullable)containerName
59 contextID:(NSString*)contextID
60 epoch:(uint64_t)epoch
61 isInitiator:(BOOL)isInitiator
62 {
63 self = [super init];
64 if (self){
65 self.protocolType = protocolType;
66 self.uniqueDeviceID = uniqueDeviceID;
67 self.uniqueClientID = uniqueClientID;
68 self.contextID = contextID;
69 self.containerName = containerName;
70 self.isInitiator = isInitiator;
71 self.pairingUUID = pairingUUID;
72 self.epoch = epoch;
73
74 _timeout = 0;
75 }
76 return self;
77 }
78
79 - (void)encodeWithCoder:(nonnull NSCoder *)coder {
80 [coder encodeObject:_protocolType forKey:@"protocolType"];
81 [coder encodeObject:_uniqueClientID forKey:@"uniqueClientID"];
82 [coder encodeObject:_uniqueDeviceID forKey:@"uniqueDeviceID"];
83 [coder encodeObject:_contextID forKey:@"contextID"];
84 [coder encodeObject:_containerName forKey:@"containerName"];
85 [coder encodeBool:_isInitiator forKey:@"isInitiator"];
86 [coder encodeObject:_pairingUUID forKey:@"pairingUUID"];
87 [coder encodeInt64:_epoch forKey:@"epoch"];
88 [coder encodeInt64:_timeout forKey:@"timeout"];
89 }
90
91 - (nullable instancetype)initWithCoder:(nonnull NSCoder *)decoder {
92 self = [super init];
93 if (self) {
94 _protocolType = [decoder decodeObjectOfClass:[NSString class] forKey:@"protocolType"];
95 _uniqueClientID = [decoder decodeObjectOfClass:[NSString class] forKey:@"uniqueClientID"];
96 _uniqueDeviceID = [decoder decodeObjectOfClass:[NSString class] forKey:@"uniqueDeviceID"];
97 _contextID = [decoder decodeObjectOfClass:[NSString class] forKey:@"contextID"];
98 _containerName = [decoder decodeObjectOfClass:[NSString class] forKey:@"containerName"];
99 _isInitiator = [decoder decodeBoolForKey:@"isInitiator"];
100 _pairingUUID = [decoder decodeObjectOfClass:[NSString class] forKey:@"pairingUUID"];
101 _epoch = [decoder decodeInt64ForKey:@"epoch"];
102 _timeout = [decoder decodeInt64ForKey:@"timeout"];
103 }
104 return self;
105 }
106
107 @end
108 NS_ASSUME_NONNULL_END
109
110 #endif /* __OBJC2__ */