From 719eb543a8d08c4f536ea7933ffb3af0a8553e87 Mon Sep 17 00:00:00 2001 From: Chris Ballinger Date: Fri, 8 Apr 2016 17:24:41 -0700 Subject: Xcode, podspec, wrapper --- xcode/OLMKit/OLMUtility.m | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 xcode/OLMKit/OLMUtility.m (limited to 'xcode/OLMKit/OLMUtility.m') diff --git a/xcode/OLMKit/OLMUtility.m b/xcode/OLMKit/OLMUtility.m new file mode 100644 index 0000000..0148932 --- /dev/null +++ b/xcode/OLMKit/OLMUtility.m @@ -0,0 +1,28 @@ +// +// OLMUtility.m +// olm +// +// Created by Chris Ballinger on 4/8/16. +// +// + +#import "OLMUtility.h" + +@implementation OLMUtility + ++ (NSData*) randomBytesOfLength:(NSUInteger)length { + uint8_t *randomBytes = malloc(length * sizeof(uint8_t)); + NSParameterAssert(randomBytes != NULL); + if (!randomBytes) { + return nil; + } + int result = SecRandomCopyBytes(kSecRandomDefault, length, randomBytes); + if (result != 0) { + free(randomBytes); + return nil; + } + NSData *data = [NSData dataWithBytesNoCopy:randomBytes length:length freeWhenDone:YES]; + return data; +} + +@end -- cgit v1.2.3 From f505113fb7a6d61015ad8050b3fb4e26df029150 Mon Sep 17 00:00:00 2001 From: Chris Ballinger Date: Sat, 9 Apr 2016 14:00:30 -0700 Subject: Initial test passing --- xcode/OLMKit/OLMUtility.m | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'xcode/OLMKit/OLMUtility.m') 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 -- cgit v1.2.3