olm/xcode/OLMKit/OLMUtility.m

29 lines
610 B
Matlab
Raw Normal View History

2016-04-09 02:24:41 +02:00
//
// 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