From b0fd1b43e3aed144b3ecbfd8ce04179001471168 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sat, 18 Nov 2023 22:01:54 +0100 Subject: [PATCH] Use safe json dictionary value extraction. --- Source/ARTTokenRequest.m | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Source/ARTTokenRequest.m b/Source/ARTTokenRequest.m index 4b088f9cd..2787879f7 100644 --- a/Source/ARTTokenRequest.m +++ b/Source/ARTTokenRequest.m @@ -2,6 +2,7 @@ #import "ARTTokenParams.h" #import "ARTAuth+Private.h" #import "ARTDefault.h" +#import "ARTNSDictionary+ARTDictionaryUtil.h" @implementation ARTTokenRequest @@ -37,17 +38,19 @@ + (ARTTokenRequest *_Nullable)fromJson:(id)json error:(NSErro return nil; } - ARTTokenParams *tokenParams = [[ARTTokenParams alloc] initWithClientId:dict[@"clientId"]]; + ARTTokenParams *tokenParams = [[ARTTokenParams alloc] initWithClientId:[dict artString:@"clientId"]]; ARTTokenRequest *tokenRequest = [[ARTTokenRequest alloc] initWithTokenParams:tokenParams - keyName:dict[@"keyName"] - nonce:dict[@"nonce"] - mac:dict[@"mac"]]; - tokenRequest.clientId = dict[@"clientId"]; - tokenRequest.ttl = dict[@"ttl"] ? [NSNumber numberWithDouble:millisecondsToTimeInterval([dict[@"ttl"] unsignedLongLongValue])] : nil; - tokenRequest.capability = dict[@"capability"]; - tokenRequest.timestamp = [NSDate dateWithTimeIntervalSince1970:[dict[@"timestamp"] doubleValue] / 1000]; + keyName:[dict artString:@"keyName"] + nonce:[dict artString:@"nonce"] + mac:[dict artString:@"mac"]]; + tokenRequest.clientId = [dict artString:@"clientId"]; + tokenRequest.capability = [dict artString:@"capability"]; + tokenRequest.timestamp = [NSDate dateWithTimeIntervalSince1970:[[dict artNumber:@"timestamp"] doubleValue] / 1000]; + NSNumber *ttlNumber = [dict artNumber:@"ttl"]; + tokenRequest.ttl = ttlNumber != nil ? [NSNumber numberWithDouble:millisecondsToTimeInterval([ttlNumber unsignedLongLongValue])] : nil; + return tokenRequest; }