Add NSCopying, NSSecureCoding Support to Informational Classes (#17)

* Add NSCopying, NSSecureCoding Support to Informational Classes

* Remove Redundant Copies

* Revert out-of-context typo corrections

* Revert out-of-context changes
This commit is contained in:
Jonathan Downing
2017-09-16 17:42:57 +03:00
committed by Sergey Abramchuk
parent 8e387bfb98
commit 270d5b8cac
10 changed files with 299 additions and 49 deletions
+32 -4
View File
@@ -10,15 +10,43 @@
using namespace openvpn;
@interface OpenVPNSessionToken ()
@property (nullable, readwrite, nonatomic) NSString *username;
@property (nullable, readwrite, nonatomic) NSString *session;
@end
@implementation OpenVPNSessionToken
- (instancetype)initWithSessionToken:(ClientAPI::SessionToken)token {
self = [super init];
if (self) {
_username = !token.username.empty() ? [NSString stringWithUTF8String:token.username.c_str()] : nil;
_session = !token.session_id.empty() ? [NSString stringWithUTF8String:token.session_id.c_str()] : nil;
if ((self = [super init])) {
self.username = !token.username.empty() ? [NSString stringWithUTF8String:token.username.c_str()] : nil;
self.session = !token.session_id.empty() ? [NSString stringWithUTF8String:token.session_id.c_str()] : nil;
}
return self;
}
- (nonnull id)copyWithZone:(nullable NSZone *)zone {
OpenVPNSessionToken *token = [[OpenVPNSessionToken allocWithZone:zone] init];
token.username = [self.username copyWithZone:zone];
token.session = [self.session copyWithZone:zone];
return token;
}
- (void)encodeWithCoder:(nonnull NSCoder *)aCoder {
[aCoder encodeObject:self.username forKey:NSStringFromSelector(@selector(username))];
[aCoder encodeObject:self.session forKey:NSStringFromSelector(@selector(session))];
}
- (nullable instancetype)initWithCoder:(nonnull NSCoder *)aDecoder {
if ((self = [self init])) {
self.username = [aDecoder decodeObjectOfClass:[NSString class] forKey:NSStringFromSelector(@selector(username))];
self.session = [aDecoder decodeObjectOfClass:[NSString class] forKey:NSStringFromSelector(@selector(session))];
}
return self;
}
+ (BOOL)supportsSecureCoding {
return YES;
}
@end