Skip to content

Commit

Permalink
[FIX] Do not throw an error when encrypting symmetrically and there’s…
Browse files Browse the repository at this point in the history
… no pubring.

Use FAILURE status code to detect encrypt/sign errors.
GPGErrorCancelled is more important than other error codes.
[#160 state:fixed assigned:mento]
  • Loading branch information
Mento committed Mar 27, 2018
1 parent 477bea2 commit 0aa382c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions Source/GPGController.m
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,16 @@ - (void)processTo:(GPGStream *)output data:(GPGStream *)input withEncryptSignMod
gpgTask.outStream = output;
[gpgTask setInput:input];

// Check outData because gpg sometime returns an exitcode != 0, but the data is correct encrypted/signed.
if (([gpgTask start] != 0 && gpgTask.outData.length == 0) || gpgTask.errorCode) {
@throw [GPGException exceptionWithReason:localizedLibmacgpgString(@"Encrypt/sign failed!") gpgTask:gpgTask];
[gpgTask start];

// The status FAILURE is issued, whenever a sign or encrypt operation failed.
// gpgTask.errorCode is always set when FAILURE was issued.
// It is better to only use FAILURE and ignore exitcode and other status codes.
if (gpgTask.errorCode) {
NSArray *failures = gpgTask.statusDict[@"FAILURE"];
if ([failures isKindOfClass:[NSArray class]] && failures.count > 0) {
@throw [GPGException exceptionWithReason:localizedLibmacgpgString(@"Encrypt/sign failed!") gpgTask:gpgTask];
}
}
} @catch (NSException *e) {
[self handleException:e];
Expand Down
3 changes: 2 additions & 1 deletion Source/GPGTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ - (void)setErrorCode:(int)value {
NSNumber *code = [NSNumber numberWithInt:value];
if (![errorCodes containsObject:code]) {
[errorCodes addObject:code];
if (!errorCode) {
// GPGErrorCancelled is the most important error code.
if (!errorCode || (value & 0xFFFF) == GPGErrorCancelled) {
errorCode = value;
}
}
Expand Down

0 comments on commit 0aa382c

Please sign in to comment.