PGPException is not thrown during secret key reading

This commit is contained in:
Paul Schaub 2021-08-15 15:27:12 +02:00
parent 6251e01d57
commit 2bd71617bd
3 changed files with 22 additions and 22 deletions

View File

@ -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));
}

View File

@ -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.");
}
}

View File

@ -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();
}
}
};
}
}