Move the secure-random code into this project due to build issues with the module, which is no longer maintained
This commit is contained in:
parent
2c73703d7d
commit
a56cae626a
12 changed files with 110 additions and 18 deletions
27
ios/AppSecureRandomModule.m
Normal file
27
ios/AppSecureRandomModule.m
Normal file
|
@ -0,0 +1,27 @@
|
|||
#import "AppSecureRandomModule.h"
|
||||
|
||||
@implementation AppSecureRandomModule
|
||||
|
||||
RCT_EXPORT_MODULE();
|
||||
|
||||
+ (BOOL)requiresMainQueueSetup
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
RCT_REMAP_METHOD(generateSecureRandomAsBase64,
|
||||
withLength:(int)length
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject)
|
||||
{
|
||||
NSMutableData* bytes = [NSMutableData dataWithLength:length];
|
||||
int result = SecRandomCopyBytes(kSecRandomDefault,length, [bytes mutableBytes]);
|
||||
if (result == errSecSuccess) {
|
||||
resolve([bytes base64EncodedStringWithOptions:0]);
|
||||
} else {
|
||||
NSError *error = [NSError errorWithDomain:@"RNSecureRandom" code:result userInfo: nil];
|
||||
reject(@"randombytes_error", @"Error generating random bytes", error);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
Loading…
Add table
Add a link
Reference in a new issue