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