1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 22:32:07 +01:00

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 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); return readPublicKeyRing(inputStream);
} }
@ -65,15 +65,15 @@ public class KeyRingReader {
return publicKeyRingCollection(asciiArmored.getBytes(UTF8)); 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); 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)); 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)); return secretKeyRing(asciiArmored.getBytes(UTF8));
} }

View file

@ -122,7 +122,7 @@ public class RejectWeakSymmetricAlgorithmDuringDecryption {
static { static {
try { try {
secretKeys = PGPainless.readKeyRing().secretKeyRing(key); secretKeys = PGPainless.readKeyRing().secretKeyRing(key);
} catch (IOException | PGPException e) { } catch (IOException e) {
fail("Secret key cannot be parsed."); fail("Secret key cannot be parsed.");
} }
} }

View file

@ -41,23 +41,23 @@ public class ExtractCertImpl implements ExtractCert {
@Override @Override
public Ready key(InputStream keyInputStream) throws IOException, SOPGPException.BadData { public Ready key(InputStream keyInputStream) throws IOException, SOPGPException.BadData {
try { PGPSecretKeyRing key = PGPainless.readKeyRing().secretKeyRing(keyInputStream);
PGPSecretKeyRing key = PGPainless.readKeyRing().secretKeyRing(keyInputStream); if (key == null) {
PGPPublicKeyRing cert = KeyRingUtils.publicKeyRingFrom(key); throw new SOPGPException.BadData(new PGPException("No key data found."));
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);
} }
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();
}
}
};
} }
} }