-
Notifications
You must be signed in to change notification settings - Fork 95
/
RNRandomBytes.m
48 lines (39 loc) · 1.04 KB
/
RNRandomBytes.m
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// RNRandom.m
// randombytes
//
// Created by Mark Vayngrib on 10/13/15.
// Copyright (c) 2015 Facebook. All rights reserved.
//
#import "RNRandomBytes.h"
#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#elif __has_include("RCTBridgeModule.h")
#import "RCTBridgeModule.h"
#else
#import "React/RCTBridgeModule.h" // Required when used as a Pod in a Swift project
#endif
@implementation RNRandomBytes
RCT_EXPORT_MODULE()
@synthesize bridge = _bridge;
RCT_EXPORT_METHOD(randomBytes:(NSUInteger)length
callback:(RCTResponseSenderBlock)callback)
{
callback(@[[NSNull null], [self randomBytes:length]]);
}
- (NSString *) randomBytes:(NSUInteger)length
{
NSMutableData* bytes = [NSMutableData dataWithLength:length];
SecRandomCopyBytes(kSecRandomDefault, length, [bytes mutableBytes]);
return [bytes base64EncodedStringWithOptions:0];
}
- (NSDictionary *)constantsToExport
{
return @{
@"seed": [self randomBytes:4096]
};
};
+ (BOOL)requiresMainQueueSetup {
return YES;
}
@end