From 005b9d477a70b0007565c0e81c7edbb6e85a812e Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 3 May 2023 17:23:13 +0200 Subject: [PATCH] KeyRingReader: Remove unused @throws IOException --- .../PGPHashContextContentSignerBuilder.java | 11 ++++------- .../secretkeyring/SecretKeyRingEditorInterface.java | 2 +- .../org/pgpainless/key/parsing/KeyRingReader.java | 10 +++++----- .../java/org/pgpainless/signature/SignatureUtils.java | 2 +- .../CachingBcPublicKeyDataDecryptorFactoryTest.java | 6 +----- .../key/collection/PGPKeyRingCollectionTest.java | 2 +- .../src/main/java/org/pgpainless/sop/EncryptImpl.java | 2 +- .../src/main/java/org/pgpainless/sop/KeyReader.java | 4 ---- 8 files changed, 14 insertions(+), 25 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/PGPHashContextContentSignerBuilder.java b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/PGPHashContextContentSignerBuilder.java index 2ea36206..7b8529fe 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/PGPHashContextContentSignerBuilder.java +++ b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/PGPHashContextContentSignerBuilder.java @@ -4,9 +4,9 @@ package org.pgpainless.encryption_signing; -import java.io.IOException; import java.io.OutputStream; import java.security.MessageDigest; +import javax.annotation.Nonnull; import org.bouncycastle.crypto.Digest; import org.bouncycastle.crypto.Signer; @@ -23,18 +23,15 @@ abstract class PGPHashContextContentSignerBuilder implements PGPContentSignerBui this.sig = sig; } - public void write(byte[] bytes, int off, int len) - throws IOException { + public void write(@Nonnull byte[] bytes, int off, int len) { sig.update(bytes, off, len); } - public void write(byte[] bytes) - throws IOException { + public void write(@Nonnull byte[] bytes) { sig.update(bytes, 0, bytes.length); } - public void write(int b) - throws IOException { + public void write(int b) { sig.update((byte) b); } } diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/modification/secretkeyring/SecretKeyRingEditorInterface.java b/pgpainless-core/src/main/java/org/pgpainless/key/modification/secretkeyring/SecretKeyRingEditorInterface.java index 7014d518..712193ee 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/modification/secretkeyring/SecretKeyRingEditorInterface.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/modification/secretkeyring/SecretKeyRingEditorInterface.java @@ -188,7 +188,7 @@ public interface SecretKeyRingEditorInterface { @Nonnull SecretKeyRingProtector primaryKeyProtector, @Nonnull KeyFlag keyFlag, KeyFlag... additionalKeyFlags) - throws PGPException, IOException, NoSuchAlgorithmException; + throws PGPException, IOException; /** * Revoke the key ring. diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java b/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java index 50cacf05..573cbda1 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java @@ -88,12 +88,12 @@ public class KeyRingReader { } public PGPPublicKeyRingCollection publicKeyRingCollection(@Nonnull InputStream inputStream) - throws IOException, PGPException { + throws IOException { return readPublicKeyRingCollection(inputStream); } public PGPPublicKeyRingCollection publicKeyRingCollection(@Nonnull byte[] bytes) - throws IOException, PGPException { + throws IOException { return publicKeyRingCollection(new ByteArrayInputStream(bytes)); } @@ -118,17 +118,17 @@ public class KeyRingReader { } public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull InputStream inputStream) - throws IOException, PGPException { + throws IOException { return readSecretKeyRingCollection(inputStream); } public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull byte[] bytes) - throws IOException, PGPException { + throws IOException { return secretKeyRingCollection(new ByteArrayInputStream(bytes)); } public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull String asciiArmored) - throws IOException, PGPException { + throws IOException { return secretKeyRingCollection(asciiArmored.getBytes(UTF8)); } diff --git a/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java b/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java index 2b69a832..a232dbab 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java +++ b/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java @@ -243,7 +243,7 @@ public final class SignatureUtils { * @throws IOException in case of a stream error * @throws PGPException in case of an OpenPGP error */ - public static List readSignatures(InputStream inputStream, int maxIterations) throws IOException, PGPException { + public static List readSignatures(InputStream inputStream, int maxIterations) throws IOException { List signatures = new ArrayList<>(); InputStream pgpIn = ArmorUtils.getDecoderStream(inputStream); PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(pgpIn); diff --git a/pgpainless-core/src/test/java/org/bouncycastle/CachingBcPublicKeyDataDecryptorFactoryTest.java b/pgpainless-core/src/test/java/org/bouncycastle/CachingBcPublicKeyDataDecryptorFactoryTest.java index e57df5d9..1bb043ca 100644 --- a/pgpainless-core/src/test/java/org/bouncycastle/CachingBcPublicKeyDataDecryptorFactoryTest.java +++ b/pgpainless-core/src/test/java/org/bouncycastle/CachingBcPublicKeyDataDecryptorFactoryTest.java @@ -7,8 +7,6 @@ package org.bouncycastle; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.security.InvalidAlgorithmParameterException; -import java.security.NoSuchAlgorithmException; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPrivateKey; @@ -25,8 +23,6 @@ import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.UnlockSecretKey; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class CachingBcPublicKeyDataDecryptorFactoryTest { private static final String KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + @@ -64,7 +60,7 @@ public class CachingBcPublicKeyDataDecryptorFactoryTest { "-----END PGP MESSAGE-----"; @Test - public void test() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException { + public void test() throws PGPException, IOException { PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY); SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys(); KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/collection/PGPKeyRingCollectionTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/collection/PGPKeyRingCollectionTest.java index 5a5a8471..89b0fccf 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/collection/PGPKeyRingCollectionTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/collection/PGPKeyRingCollectionTest.java @@ -56,7 +56,7 @@ public class PGPKeyRingCollectionTest { } @Test - public void testConstructorFromCollection() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException { + public void testConstructorFromCollection() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { PGPSecretKeyRing first = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit"); PGPSecretKeyRing second = PGPainless.generateKeyRing().simpleEcKeyRing("bob@the-builder.tv"); PGPPublicKeyRing secondPub = KeyRingUtils.publicKeyRingFrom(second); diff --git a/pgpainless-sop/src/main/java/org/pgpainless/sop/EncryptImpl.java b/pgpainless-sop/src/main/java/org/pgpainless/sop/EncryptImpl.java index 18bcabcc..da895aed 100644 --- a/pgpainless-sop/src/main/java/org/pgpainless/sop/EncryptImpl.java +++ b/pgpainless-sop/src/main/java/org/pgpainless/sop/EncryptImpl.java @@ -113,7 +113,7 @@ public class EncryptImpl implements Encrypt { encryptionOptions.addRecipients(certificates); } catch (KeyException.UnacceptableEncryptionKeyException e) { throw new SOPGPException.CertCannotEncrypt(e.getMessage(), e); - } catch (IOException | PGPException e) { + } catch (IOException e) { throw new SOPGPException.BadData(e); } return this; diff --git a/pgpainless-sop/src/main/java/org/pgpainless/sop/KeyReader.java b/pgpainless-sop/src/main/java/org/pgpainless/sop/KeyReader.java index 036ec126..786a715c 100644 --- a/pgpainless-sop/src/main/java/org/pgpainless/sop/KeyReader.java +++ b/pgpainless-sop/src/main/java/org/pgpainless/sop/KeyReader.java @@ -33,8 +33,6 @@ class KeyReader { throw new SOPGPException.BadData(e); } throw e; - } catch (PGPException e) { - throw new SOPGPException.BadData("Cannot read keys.", e); } if (requireContent && (keys == null || keys.size() == 0)) { @@ -54,8 +52,6 @@ class KeyReader { throw new SOPGPException.BadData(e); } throw e; - } catch (PGPException e) { - throw new SOPGPException.BadData(e); } if (requireContent && (certs == null || certs.size() == 0)) { throw new SOPGPException.BadData(new PGPException("No cert data found."));