Skip to content

Commit

Permalink
updated version
Browse files Browse the repository at this point in the history
  • Loading branch information
jerson committed Nov 10, 2020
1 parent 27b3893 commit b8d205a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 18 deletions.
Binary file modified ios/Openpgp.framework.zip
Binary file not shown.
99 changes: 82 additions & 17 deletions ios/RNFastOpenPGP.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,44 @@ - (dispatch_queue_t)methodQueue
return dispatch_queue_create("fast-openpgp", DISPATCH_QUEUE_SERIAL);
}

- (OpenpgpFileHints *)getFileHints:(NSDictionary *)map
{
OpenpgpFileHints * options = [[OpenpgpFileHints alloc] init];
if (map == nil){
return options;
}
if(map[@"isBinary"]){
[options setIsBinary:[map[@"isBinary"] boolValue]];
}
if(map[@"fileName"]){
[options setFileName:map[@"fileName"]];
}
if(map[@"modTime"]){
[options setModTime:map[@"modTime"]];
}

return options;
}

- (OpenpgpEntity *)getEntity:(NSDictionary *)map
{
OpenpgpEntity * options = [[OpenpgpEntity alloc] init];
if (map == nil){
return nil;
}
if(map[@"publicKey"]){
[options setPublicKey:map[@"publicKey"]];
}
if(map[@"privateKey"]){
[options setPrivateKey:map[@"privateKey"]];
}
if(map[@"passphrase"]){
[options setPassphrase:map[@"passphrase"]];
}

return options;
}

- (OpenpgpKeyOptions *)getKeyOptions:(NSDictionary *)map
{
OpenpgpKeyOptions * options = [[OpenpgpKeyOptions alloc] init];
Expand All @@ -42,6 +80,9 @@ - (OpenpgpKeyOptions *)getKeyOptions:(NSDictionary *)map
if(map[@"RSABits"]){
[options setRSABitsFromString:[NSString stringWithFormat:@"%.0f",[map[@"RSABits"] floatValue]]];
}
if(map[@"rsaBits"]){
[options setRSABitsFromString:[NSString stringWithFormat:@"%.0f",[map[@"rsaBits"] floatValue]]];
}
if(map[@"compressionLevel"]){
[options setCompressionLevelFromString:[NSString stringWithFormat:@"%.0f",[map[@"compressionLevel"] floatValue]]];
}
Expand Down Expand Up @@ -79,12 +120,18 @@ - (OpenpgpOptions *)getOptions:(NSDictionary *)map
RCT_REMAP_METHOD(encrypt,
encryptWith: (NSString *)message
publicKey: (NSString *)publicKey
entity:(NSDictionary *)entityMap
fileHints:(NSDictionary *)fileHintsMap
options:(NSDictionary *)optionsMap
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@try {
OpenpgpEntity * entity = [self getEntity:entityMap];
OpenpgpFileHints * fileHints = [self getFileHints:fileHintsMap];
OpenpgpKeyOptions *options = [self getKeyOptions:optionsMap];
NSError *error;
NSString * output = [[self instance] encrypt:message publicKey:publicKey error:&error];
NSString * output = [[self instance] encrypt:message publicKey:publicKey signedEntity:entity fileHints:fileHints options:options error:&error];

if(error!=nil){
reject([NSString stringWithFormat:@"%ld",[error code]], [error description],error);
Expand All @@ -102,13 +149,19 @@ - (OpenpgpOptions *)getOptions:(NSDictionary *)map
encryptFileWith: (NSString *)inputFile
outputFile: (NSString *)outputFile
publicKey: (NSString *)publicKey
entity:(NSDictionary *)entityMap
fileHints:(NSDictionary *)fileHintsMap
options:(NSDictionary *)optionsMap
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@try {
OpenpgpEntity * entity = [self getEntity:entityMap];
OpenpgpFileHints * fileHints = [self getFileHints:fileHintsMap];
OpenpgpKeyOptions *options = [self getKeyOptions:optionsMap];
NSError *error;
NSData *dataFromFile = [NSData dataWithContentsOfFile:inputFile];
NSData *output = [[self instance] encryptBytes:dataFromFile publicKey:publicKey error:&error];
NSData *output = [[self instance] encryptBytes:dataFromFile publicKey:publicKey signedEntity:entity fileHints:fileHints options:options error:&error];

[output writeToFile:outputFile atomically:YES];

Expand All @@ -127,12 +180,14 @@ - (OpenpgpOptions *)getOptions:(NSDictionary *)map
decryptWith: (NSString *)message
privateKey: (NSString *)privateKey
passphrase: (NSString *)passphrase
options:(NSDictionary *)optionsMap
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@try {
OpenpgpKeyOptions *options = [self getKeyOptions:optionsMap];
NSError *error;
NSString * output = [[self instance] decrypt:message privateKey:privateKey passphrase:passphrase error:&error];
NSString * output = [[self instance] decrypt:message privateKey:privateKey passphrase:passphrase options:options error:&error];

if(error!=nil){
reject([NSString stringWithFormat:@"%ld",(long)[error code]], [error description],error);
Expand All @@ -150,13 +205,15 @@ - (OpenpgpOptions *)getOptions:(NSDictionary *)map
outputFile: (NSString *)outputFile
privateKey: (NSString *)privateKey
passphrase: (NSString *)passphrase
options:(NSDictionary *)optionsMap
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@try {
OpenpgpKeyOptions *options = [self getKeyOptions:optionsMap];
NSError *error;
NSData *dataFromFile = [NSData dataWithContentsOfFile:inputFile];
NSData *output = [[self instance] decryptBytes:dataFromFile privateKey:privateKey passphrase:passphrase error:&error];
NSData *output = [[self instance] decryptBytes:dataFromFile privateKey:privateKey passphrase:passphrase options:options error:&error];

[output writeToFile:outputFile atomically:YES];

Expand All @@ -176,12 +233,14 @@ - (OpenpgpOptions *)getOptions:(NSDictionary *)map
publicKey: (NSString *)publicKey
privateKey: (NSString *)privateKey
passphrase: (NSString *)passphrase
options:(NSDictionary *)optionsMap
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@try {
OpenpgpKeyOptions *options = [self getKeyOptions:optionsMap];
NSError *error;
NSString * output = [[self instance] sign:message publicKey:publicKey privateKey:privateKey passphrase:passphrase error:&error];
NSString * output = [[self instance] sign:message publicKey:publicKey privateKey:privateKey passphrase:passphrase options:options error:&error];

if(error!=nil){
reject([NSString stringWithFormat:@"%ld",(long)[error code]], [error description],error);
Expand All @@ -199,13 +258,15 @@ - (OpenpgpOptions *)getOptions:(NSDictionary *)map
publicKey: (NSString *)publicKey
privateKey: (NSString *)privateKey
passphrase: (NSString *)passphrase
options:(NSDictionary *)optionsMap
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@try {
OpenpgpKeyOptions *options = [self getKeyOptions:optionsMap];
NSError *error;
NSData *dataFromFile = [NSData dataWithContentsOfFile:inputFile];
NSString * output = [[self instance] signBytesToString:dataFromFile publicKey:publicKey privateKey:privateKey passphrase:passphrase error:&error];
NSString * output = [[self instance] signBytesToString:dataFromFile publicKey:publicKey privateKey:privateKey passphrase:passphrase options:options error:&error];

if(error!=nil){
reject([NSString stringWithFormat:@"%ld",(long)[error code]], [error description],error);
Expand Down Expand Up @@ -267,9 +328,9 @@ - (OpenpgpOptions *)getOptions:(NSDictionary *)map


RCT_REMAP_METHOD(decryptSymmetric,
decryptSymmetricWith: (NSString *)message
passphrase: (NSString *)passphrase
options:(NSDictionary *)map
decryptSymmetricWith: (NSString *)message
passphrase: (NSString *)passphrase
options:(NSDictionary *)map
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
Expand All @@ -291,10 +352,10 @@ - (OpenpgpOptions *)getOptions:(NSDictionary *)map


RCT_REMAP_METHOD(decryptSymmetricFile,
decryptSymmetricFileWith: (NSString *)inputFile
outputFile: (NSString *)outputFile
passphrase: (NSString *)passphrase
options:(NSDictionary *)map
decryptSymmetricFileWith: (NSString *)inputFile
outputFile: (NSString *)outputFile
passphrase: (NSString *)passphrase
options:(NSDictionary *)map
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
Expand All @@ -320,14 +381,16 @@ - (OpenpgpOptions *)getOptions:(NSDictionary *)map
RCT_REMAP_METHOD(encryptSymmetric,
encryptSymmetricWith: (NSString *)message
passphrase: (NSString *)passphrase
fileHints:(NSDictionary *)fileHintsMap
options:(NSDictionary *)map
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@try {
OpenpgpFileHints * fileHints = [self getFileHints:fileHintsMap];
OpenpgpKeyOptions *options = [self getKeyOptions:map];
NSError *error;
NSString * output = [[self instance] encryptSymmetric:message passphrase:passphrase options:options error:&error];
NSString * output = [[self instance] encryptSymmetric:message passphrase:passphrase fileHints:fileHints options:options error:&error];

if(error!=nil){
reject([NSString stringWithFormat:@"%ld",(long)[error code]], [error description],error);
Expand All @@ -345,15 +408,17 @@ - (OpenpgpOptions *)getOptions:(NSDictionary *)map
encryptSymmetricFileWith: (NSString *)inputFile
outputFile: (NSString *)outputFile
passphrase: (NSString *)passphrase
fileHints:(NSDictionary *)fileHintsMap
options:(NSDictionary *)map
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@try {
OpenpgpFileHints * fileHints = [self getFileHints:fileHintsMap];
OpenpgpKeyOptions *options = [self getKeyOptions:map];
NSError *error;
NSData *dataFromFile = [NSData dataWithContentsOfFile:inputFile];
NSData * output = [[self instance] encryptSymmetricBytes:dataFromFile passphrase:passphrase options:options error:&error];
NSData * output = [[self instance] encryptSymmetricBytes:dataFromFile passphrase:passphrase fileHints:fileHints options:options error:&error];
[output writeToFile:outputFile atomically:YES];

if(error!=nil){
Expand Down Expand Up @@ -382,8 +447,8 @@ - (OpenpgpOptions *)getOptions:(NSDictionary *)map
reject([NSString stringWithFormat:@"%ld",(long)[error code]], [error description],error);
}else{
resolve(@{
@"publicKey":output.publicKey,
@"privateKey":output.privateKey,
@"publicKey":output.publicKey,
@"privateKey":output.privateKey,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-fast-openpgp",
"version": "1.5.2",
"version": "1.6.0",
"description": "library for use openPGP",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down

0 comments on commit b8d205a

Please sign in to comment.