From 1fd0459e4beb6f5a7916379db56f9ab11a24cc19 Mon Sep 17 00:00:00 2001 From: Justin Peckner Date: Tue, 8 Oct 2019 12:38:02 -0700 Subject: [PATCH] Fixes bug where state variable was always a string of zeros in Release builds (or other builds where assertions are disabled) --- CleverSDK/CleverSDK.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CleverSDK/CleverSDK.m b/CleverSDK/CleverSDK.m index 3f5015e..29b8923 100755 --- a/CleverSDK/CleverSDK.m +++ b/CleverSDK/CleverSDK.m @@ -42,14 +42,18 @@ + (void)startWithClientId:(NSString *)clientId RedirectURI:(NSString *)redirectU + (NSString *)generateRandomString:(int)length { NSAssert(length % 2 == 0, @"Must generate random string with even length"); + NSMutableData *data = [NSMutableData dataWithLength:length / 2]; - NSAssert(SecRandomCopyBytes(kSecRandomDefault, length, [data mutableBytes]) == 0, @"Failure in SecRandomCopyBytes: %d", errno); + int errorCode __unused = SecRandomCopyBytes(kSecRandomDefault, length, [data mutableBytes]); + NSAssert(errorCode == 0, @"Failure in SecRandomCopyBytes: %d", errorCode); + NSMutableString *hexString = [NSMutableString stringWithCapacity:(length)]; const unsigned char *dataBytes = [data bytes]; for (int i = 0; i < length / 2; ++i) { [hexString appendFormat:@"%02x", (unsigned int)dataBytes[i]]; } + return [NSString stringWithString:hexString]; }