1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-16 01:12:05 +01:00

Further refactoring of SignatureVerifyingInputStream

This commit is contained in:
Paul Schaub 2020-01-10 18:31:43 +01:00
parent 2902c81b6c
commit b615ef74b0
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -66,17 +66,23 @@ public class SignatureVerifyingInputStream extends FilterInputStream {
} }
} }
private void validateOnePassSignatures() throws IOException { private void validateOnePassSignaturesIfNeeded() throws IOException {
if (validated) { if (validated) {
return; return;
} }
validated = true; validated = true;
validateOnePassSignaturesIfAny();
}
private void validateOnePassSignaturesIfAny() throws IOException {
if (onePassSignatures.isEmpty()) { if (onePassSignatures.isEmpty()) {
LOGGER.log(LEVEL, "No One-Pass-Signatures found -> No validation"); LOGGER.log(LEVEL, "No One-Pass-Signatures found -> No validation");
return; return;
} }
validateOnePassSignatures();
}
private void validateOnePassSignatures() throws IOException {
PGPSignatureList signatureList = findPgpSignatureList(); PGPSignatureList signatureList = findPgpSignatureList();
try { try {
@ -95,7 +101,6 @@ public class SignatureVerifyingInputStream extends FilterInputStream {
} catch (PGPException | SignatureException e) { } catch (PGPException | SignatureException e) {
throw new IOException(e.getMessage(), e); throw new IOException(e.getMessage(), e);
} }
} }
private void verifySignatureOrThrowSignatureException(PGPSignature signature, OpenPgpV4Fingerprint fingerprint, PGPOnePassSignature onePassSignature) throws PGPException, SignatureException { 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 int data = super.read();
final boolean endOfStream = data == -1; final boolean endOfStream = data == -1;
if (endOfStream) { if (endOfStream) {
validateOnePassSignatures(); validateOnePassSignaturesIfNeeded();
} else { } else {
updateOnePassSignatures((byte) data); updateOnePassSignatures((byte) data);
} }
@ -167,7 +172,7 @@ public class SignatureVerifyingInputStream extends FilterInputStream {
final boolean endOfStream = read == -1; final boolean endOfStream = read == -1;
if (endOfStream) { if (endOfStream) {
validateOnePassSignatures(); validateOnePassSignaturesIfNeeded();
} else { } else {
updateOnePassSignatures(b, off, read); updateOnePassSignatures(b, off, read);
} }