aboutsummaryrefslogtreecommitdiff
path: root/xcode/OLMKit/OLMUtility.m
blob: 01489329f6f9ffd64246b9fd37fb8d02750743b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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