From 17defe556aa831e4fdb16a1e924351142a73003f Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 6 Jul 2015 00:52:53 +0200 Subject: cleanup, NonNull annotation, never return null in PgpDecryptVerify --- .../keychain/pgp/PgpDecryptVerify.java | 36 +++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java index acac9ecff..bfe7c3474 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java @@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.pgp; import android.content.Context; +import android.support.annotation.NonNull; import android.webkit.MimeTypeMap; import org.openintents.openpgp.OpenPgpMetadata; @@ -80,9 +81,8 @@ public class PgpDecryptVerify extends BaseOperation super(context, providerHelper, progressable); } - /** - * Decrypts and/or verifies data based on parameters of class - */ + /** Decrypts and/or verifies data based on parameters of PgpDecryptVerifyInputParcel. */ + @NonNull public DecryptVerifyResult execute(PgpDecryptVerifyInputParcel input, CryptoInputParcel cryptoInput) { InputData inputData; OutputStream outputStream; @@ -96,8 +96,10 @@ public class PgpDecryptVerify extends BaseOperation long inputSize = FileHelper.getFileSize(mContext, input.getInputUri(), 0); inputData = new InputData(inputStream, inputSize); } catch (FileNotFoundException e) { - Log.e(Constants.TAG, "File not found at " + input.getInputUri(), e); - return null; + Log.e(Constants.TAG, "URI could not be opened: " + input.getInputUri(), e); + OperationLog log = new OperationLog(); + log.add(LogType.MSG_DC_ERROR_IO, 1); + return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log); } } @@ -107,8 +109,10 @@ public class PgpDecryptVerify extends BaseOperation try { outputStream = mContext.getContentResolver().openOutputStream(input.getOutputUri()); } catch (FileNotFoundException e) { - e.printStackTrace(); - return null; + Log.e(Constants.TAG, "URI could not be opened: " + input.getOutputUri(), e); + OperationLog log = new OperationLog(); + log.add(LogType.MSG_DC_ERROR_IO, 1); + return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log); } } @@ -122,11 +126,13 @@ public class PgpDecryptVerify extends BaseOperation } + @NonNull public DecryptVerifyResult execute(PgpDecryptVerifyInputParcel input, CryptoInputParcel cryptoInput, InputData inputData, OutputStream outputStream) { return executeInternal(input, cryptoInput, inputData, outputStream); } + @NonNull private DecryptVerifyResult executeInternal(PgpDecryptVerifyInputParcel input, CryptoInputParcel cryptoInput, InputData inputData, OutputStream outputStream) { try { @@ -169,9 +175,8 @@ public class PgpDecryptVerify extends BaseOperation } } - /** - * Verify Keybase.io style signed literal data - */ + /**Verify signed plaintext data (PGP/INLINE). */ + @NonNull private DecryptVerifyResult verifySignedLiteralData( PgpDecryptVerifyInputParcel input, InputStream in, OutputStream out, int indent) throws IOException, PGPException { @@ -301,9 +306,8 @@ public class PgpDecryptVerify extends BaseOperation } - /** - * Decrypt and/or verifies binary or ascii armored pgp - */ + /** Decrypt and/or verify binary or ascii armored pgp data. */ + @NonNull private DecryptVerifyResult decryptVerify( PgpDecryptVerifyInputParcel input, CryptoInputParcel cryptoInput, InputStream in, OutputStream out, int indent) throws IOException, PGPException { @@ -843,6 +847,7 @@ public class PgpDecryptVerify extends BaseOperation * The method is heavily based on * pg/src/main/java/org/spongycastle/openpgp/examples/ClearSignedFileProcessor.java */ + @NonNull private DecryptVerifyResult verifyCleartextSignature( ArmoredInputStream aIn, OutputStream outputStream, int indent) throws IOException, PGPException { @@ -950,6 +955,7 @@ public class PgpDecryptVerify extends BaseOperation return result; } + @NonNull private DecryptVerifyResult verifyDetachedSignature( PgpDecryptVerifyInputParcel input, InputData inputData, OutputStream out, int indent) throws IOException, PGPException { @@ -1042,7 +1048,9 @@ public class PgpDecryptVerify extends BaseOperation return result; } - private PGPSignature processPGPSignatureList(PGPSignatureList sigList, OpenPgpSignatureResultBuilder signatureResultBuilder) throws PGPException { + private PGPSignature processPGPSignatureList( + PGPSignatureList sigList, OpenPgpSignatureResultBuilder signatureResultBuilder) + throws PGPException { CanonicalizedPublicKeyRing signingRing = null; CanonicalizedPublicKey signingKey = null; int signatureIndex = -1; -- cgit v1.2.3