diff options
author | Chris Ballinger <chrisballinger@gmail.com> | 2016-04-09 14:00:30 -0700 |
---|---|---|
committer | Chris Ballinger <chrisballinger@gmail.com> | 2016-04-09 14:00:30 -0700 |
commit | f505113fb7a6d61015ad8050b3fb4e26df029150 (patch) | |
tree | 0bdaba8f07189f3adc828c2895ce7429d9b3cb3e /xcode/OLMKit/OLMUtility.m | |
parent | 719eb543a8d08c4f536ea7933ffb3af0a8553e87 (diff) |
Initial test passing
Diffstat (limited to 'xcode/OLMKit/OLMUtility.m')
-rw-r--r-- | xcode/OLMKit/OLMUtility.m | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/xcode/OLMKit/OLMUtility.m b/xcode/OLMKit/OLMUtility.m index 0148932..5dbe644 100644 --- a/xcode/OLMKit/OLMUtility.m +++ b/xcode/OLMKit/OLMUtility.m @@ -10,19 +10,16 @@ @implementation OLMUtility -+ (NSData*) randomBytesOfLength:(NSUInteger)length { - uint8_t *randomBytes = malloc(length * sizeof(uint8_t)); - NSParameterAssert(randomBytes != NULL); - if (!randomBytes) { ++ (NSMutableData*) randomBytesOfLength:(NSUInteger)length { + NSMutableData *randomData = [NSMutableData dataWithLength:length]; + if (!randomData) { return nil; } - int result = SecRandomCopyBytes(kSecRandomDefault, length, randomBytes); + int result = SecRandomCopyBytes(kSecRandomDefault, randomData.length, randomData.mutableBytes); if (result != 0) { - free(randomBytes); return nil; } - NSData *data = [NSData dataWithBytesNoCopy:randomBytes length:length freeWhenDone:YES]; - return data; + return randomData; } @end |