From 7de04c294971c6b166674318263386597045186a Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 24 Aug 2020 16:57:14 +0200 Subject: [PATCH] Add handy shortcut methods to the API --- .../DecryptionBuilderInterface.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionBuilderInterface.java b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionBuilderInterface.java index 45d872eb..cc41f5d6 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionBuilderInterface.java +++ b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionBuilderInterface.java @@ -16,6 +16,7 @@ package org.pgpainless.decryption_verification; import javax.annotation.Nonnull; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Collections; @@ -72,6 +73,39 @@ public interface DecryptionBuilderInterface { interface Verify extends VerifyWith { + @Override + HandleMissingPublicKeys verifyWith(@Nonnull PGPPublicKeyRingCollection publicKeyRings); + + @Override + default HandleMissingPublicKeys verifyWith(@Nonnull OpenPgpV4Fingerprint trustedFingerprint, + @Nonnull PGPPublicKeyRingCollection publicKeyRings) { + return verifyWith(Collections.singleton(trustedFingerprint), publicKeyRings); + } + + @Override + HandleMissingPublicKeys verifyWith(@Nonnull Set trustedFingerprints, + @Nonnull PGPPublicKeyRingCollection publicKeyRings); + + @Override + default HandleMissingPublicKeys verifyWith(@Nonnull PGPPublicKeyRing publicKeyRing) { + return verifyWith(Collections.singleton(publicKeyRing)); + } + + @Override + HandleMissingPublicKeys verifyWith(@Nonnull Set publicKeyRings); + + /** + * Pass in one or more detached signatures to verify. + * + * @param bytes detached signatures (ascii armored or binary). + * @return api handle + * @throws IOException if some IO error occurs + * @throws PGPException if the detached signatures are malformed + */ + default VerifyWith verifyDetachedSignature(@Nonnull byte[] bytes) throws IOException, PGPException { + return verifyDetachedSignature(new ByteArrayInputStream(bytes)); + } + /** * Pass in one or more detached signatures to verify. *