mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.4 KiB
Matlab
46 lines
1.4 KiB
Matlab
7 years ago
|
//
|
||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
9 years ago
|
|
||
|
#import "OWSDeviceProvisioningURLParser.h"
|
||
5 years ago
|
#import <SessionProtocolKit/NSData+keyVersionByte.h>
|
||
|
#import <SessionProtocolKit/NSData+OWS.h>
|
||
9 years ago
|
|
||
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
|
NSString *const OWSQueryItemNameEphemeralDeviceIdKey = @"uuid";
|
||
|
NSString *const OWSQueryItemNameEncodedPublicKeyKey = @"pub_key";
|
||
|
|
||
|
@implementation OWSDeviceProvisioningURLParser
|
||
|
|
||
|
- (instancetype)initWithProvisioningURL:(NSString *)provisioningURL
|
||
|
{
|
||
|
self = [super init];
|
||
|
if (!self) {
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
NSURLComponents *components = [NSURLComponents componentsWithString:provisioningURL];
|
||
|
for (NSURLQueryItem *queryItem in [components queryItems]) {
|
||
|
if ([queryItem.name isEqualToString:OWSQueryItemNameEphemeralDeviceIdKey]) {
|
||
|
_ephemeralDeviceId = queryItem.value;
|
||
|
} else if ([queryItem.name isEqualToString:OWSQueryItemNameEncodedPublicKeyKey]) {
|
||
|
NSString *encodedPublicKey = queryItem.value;
|
||
7 years ago
|
@try {
|
||
7 years ago
|
_publicKey = [[NSData dataFromBase64String:encodedPublicKey] throws_removeKeyType];
|
||
7 years ago
|
} @catch (NSException *exception) {
|
||
|
OWSFailDebug(@"exception: %@", exception);
|
||
|
}
|
||
9 years ago
|
} else {
|
||
7 years ago
|
OWSLogWarn(@"Unkown query item in provisioning string: %@", queryItem.name);
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
_valid = _ephemeralDeviceId && _publicKey;
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
@end
|
||
|
|
||
|
NS_ASSUME_NONNULL_END
|