darling-security/KeychainCircle/NSData+SecRandom.m
2017-06-03 12:31:08 -07:00

27 lines
487 B
Objective-C

//
// NSData+SecRandom.m
// Security
//
// Created by Mitch Adler on 4/15/16.
//
//
#import <Foundation/Foundation.h>
#import <NSData+SecRandom.h>
#include <Security/SecRandom.h>
@implementation NSMutableData (SecRandom)
+ (instancetype) dataWithRandomBytes: (int) length {
NSMutableData* result = [NSMutableData dataWithLength: length];
if (0 != SecRandomCopyBytes(kSecRandomDefault, result.length, result.mutableBytes))
return nil;
return result;
}
@end