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 0340e71c..c13ee9cb 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 @@ -40,7 +40,7 @@ public class KeyRingReader { public static final Charset UTF8 = Charset.forName("UTF-8"); - public @Nonnull PGPPublicKeyRing publicKeyRing(@Nonnull InputStream inputStream) throws IOException { + public PGPPublicKeyRing publicKeyRing(@Nonnull InputStream inputStream) throws IOException { return readPublicKeyRing(inputStream); } @@ -65,15 +65,15 @@ public class KeyRingReader { return publicKeyRingCollection(asciiArmored.getBytes(UTF8)); } - public PGPSecretKeyRing secretKeyRing(@Nonnull InputStream inputStream) throws IOException, PGPException { + public PGPSecretKeyRing secretKeyRing(@Nonnull InputStream inputStream) throws IOException { return readSecretKeyRing(inputStream); } - public PGPSecretKeyRing secretKeyRing(@Nonnull byte[] bytes) throws IOException, PGPException { + public PGPSecretKeyRing secretKeyRing(@Nonnull byte[] bytes) throws IOException { return secretKeyRing(new ByteArrayInputStream(bytes)); } - public PGPSecretKeyRing secretKeyRing(@Nonnull String asciiArmored) throws IOException, PGPException { + public PGPSecretKeyRing secretKeyRing(@Nonnull String asciiArmored) throws IOException { return secretKeyRing(asciiArmored.getBytes(UTF8)); } diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RejectWeakSymmetricAlgorithmDuringDecryption.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RejectWeakSymmetricAlgorithmDuringDecryption.java index 46c43143..635e0b2b 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RejectWeakSymmetricAlgorithmDuringDecryption.java +++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RejectWeakSymmetricAlgorithmDuringDecryption.java @@ -122,7 +122,7 @@ public class RejectWeakSymmetricAlgorithmDuringDecryption { static { try { secretKeys = PGPainless.readKeyRing().secretKeyRing(key); - } catch (IOException | PGPException e) { + } catch (IOException e) { fail("Secret key cannot be parsed."); } } diff --git a/pgpainless-sop/src/main/java/org/pgpainless/sop/ExtractCertImpl.java b/pgpainless-sop/src/main/java/org/pgpainless/sop/ExtractCertImpl.java index 20431664..b2076eb2 100644 --- a/pgpainless-sop/src/main/java/org/pgpainless/sop/ExtractCertImpl.java +++ b/pgpainless-sop/src/main/java/org/pgpainless/sop/ExtractCertImpl.java @@ -41,23 +41,23 @@ public class ExtractCertImpl implements ExtractCert { @Override public Ready key(InputStream keyInputStream) throws IOException, SOPGPException.BadData { - try { - PGPSecretKeyRing key = PGPainless.readKeyRing().secretKeyRing(keyInputStream); - PGPPublicKeyRing cert = KeyRingUtils.publicKeyRingFrom(key); - - return new Ready() { - @Override - public void writeTo(OutputStream outputStream) throws IOException { - OutputStream out = armor ? ArmorUtils.createArmoredOutputStreamFor(cert, outputStream) : outputStream; - cert.encode(out); - - if (armor) { - out.close(); - } - } - }; - } catch (PGPException e) { - throw new SOPGPException.BadData(e); + PGPSecretKeyRing key = PGPainless.readKeyRing().secretKeyRing(keyInputStream); + if (key == null) { + throw new SOPGPException.BadData(new PGPException("No key data found.")); } + + PGPPublicKeyRing cert = KeyRingUtils.publicKeyRingFrom(key); + + return new Ready() { + @Override + public void writeTo(OutputStream outputStream) throws IOException { + OutputStream out = armor ? ArmorUtils.createArmoredOutputStreamFor(cert, outputStream) : outputStream; + cert.encode(out); + + if (armor) { + out.close(); + } + } + }; } }