From b615ef74b0861787c36dec7247d476bfa6e16bf0 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 10 Jan 2020 18:31:43 +0100 Subject: [PATCH] Further refactoring of SignatureVerifyingInputStream --- .../SignatureVerifyingInputStream.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/SignatureVerifyingInputStream.java b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/SignatureVerifyingInputStream.java index eca2c75f..ee2b5c29 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/SignatureVerifyingInputStream.java +++ b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/SignatureVerifyingInputStream.java @@ -66,17 +66,23 @@ public class SignatureVerifyingInputStream extends FilterInputStream { } } - private void validateOnePassSignatures() throws IOException { + private void validateOnePassSignaturesIfNeeded() throws IOException { if (validated) { return; } validated = true; + validateOnePassSignaturesIfAny(); + } + private void validateOnePassSignaturesIfAny() throws IOException { if (onePassSignatures.isEmpty()) { LOGGER.log(LEVEL, "No One-Pass-Signatures found -> No validation"); return; } + validateOnePassSignatures(); + } + private void validateOnePassSignatures() throws IOException { PGPSignatureList signatureList = findPgpSignatureList(); try { @@ -95,7 +101,6 @@ public class SignatureVerifyingInputStream extends FilterInputStream { } catch (PGPException | SignatureException e) { throw new IOException(e.getMessage(), e); } - } private void verifySignatureOrThrowSignatureException(PGPSignature signature, OpenPgpV4Fingerprint fingerprint, PGPOnePassSignature onePassSignature) throws PGPException, SignatureException { @@ -149,7 +154,7 @@ public class SignatureVerifyingInputStream extends FilterInputStream { final int data = super.read(); final boolean endOfStream = data == -1; if (endOfStream) { - validateOnePassSignatures(); + validateOnePassSignaturesIfNeeded(); } else { updateOnePassSignatures((byte) data); } @@ -167,7 +172,7 @@ public class SignatureVerifyingInputStream extends FilterInputStream { final boolean endOfStream = read == -1; if (endOfStream) { - validateOnePassSignatures(); + validateOnePassSignaturesIfNeeded(); } else { updateOnePassSignatures(b, off, read); }