From 594d1686c92f40641f586bc0395aa833b09c22c7 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 2 Jun 2016 17:21:07 +0200 Subject: [PATCH] service: slightly clearer code for backwards compatibility --- .../keychain/remote/OpenPgpService.java | 27 +++++++------------ extern/openpgp-api-lib | 2 +- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index cd941ad72..e2d7958ec 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -557,30 +557,21 @@ public class OpenPgpService extends Service { if (signatureResult.getResult() == OpenPgpSignatureResult.RESULT_NO_SIGNATURE) { result.putExtra(OpenPgpApi.RESULT_SIGNATURE, (Parcelable[]) null); } - - // OpenPgpDecryptionResult does not exist in API < 8 - { - OpenPgpDecryptionResult decryptionResult = pgpResult.getDecryptionResult(); - - // case RESULT_NOT_ENCRYPTED, but a signature, fallback to deprecated signatureOnly variable - if (decryptionResult.getResult() == OpenPgpDecryptionResult.RESULT_NOT_ENCRYPTED - && signatureResult.getResult() != OpenPgpSignatureResult.RESULT_NO_SIGNATURE) { - // noinspection deprecation - signatureResult = signatureResult.withSignatureOnlyFlag(); - } - - // case RESULT_INSECURE, simply accept as a fallback like in previous API versions - - // case RESULT_ENCRYPTED - // nothing to do! - } } - if (data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) >= 8) { + boolean apiHasOpenPgpDecryptionResult = data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) >= 8; + if (apiHasOpenPgpDecryptionResult) { OpenPgpDecryptionResult decryptionResult = pgpResult.getDecryptionResult(); if (decryptionResult != null) { result.putExtra(OpenPgpApi.RESULT_DECRYPTION, decryptionResult); } + } else { + // this info was kept in OpenPgpSignatureResult, so put it there for compatibility + OpenPgpDecryptionResult decryptionResult = pgpResult.getDecryptionResult(); + boolean signatureOnly = decryptionResult.getResult() == OpenPgpDecryptionResult.RESULT_NOT_ENCRYPTED + && signatureResult.getResult() != OpenPgpSignatureResult.RESULT_NO_SIGNATURE; + // noinspection deprecation, this is for backwards compatibility + signatureResult = signatureResult.withSignatureOnlyFlag(signatureOnly); } OpenPgpMetadata metadata = pgpResult.getDecryptionMetadata(); diff --git a/extern/openpgp-api-lib b/extern/openpgp-api-lib index 4be4e488f..342cda1a1 160000 --- a/extern/openpgp-api-lib +++ b/extern/openpgp-api-lib @@ -1 +1 @@ -Subproject commit 4be4e488f29fa6e8b953357d047b090537703831 +Subproject commit 342cda1a17f0ff3c9e0e9bad306c7a0bb6ce7722