olm/xcode/OLMKit/OLMUtility.m
2016-04-08 17:26:12 -07:00

28 lines
610 B
Objective-C

//
// 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