1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-17 18:02:05 +01:00

Use KeyReader class when reading public or secret keys

This commit is contained in:
Paul Schaub 2023-07-12 15:25:03 +02:00
parent 744c679e0c
commit e5539a810d
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 3 additions and 8 deletions

View file

@ -14,7 +14,6 @@ import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.pgpainless.PGPainless;
import org.pgpainless.exception.MissingPassphraseException;
import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.protection.SecretKeyRingProtector;
@ -54,7 +53,7 @@ public class ChangeKeyPasswordImpl implements ChangeKeyPassword {
SecretKeyRingProtector newProtector = SecretKeyRingProtector.unlockAnyKeyWith(newPassphrase);
PGPSecretKeyRingCollection secretKeyRingCollection;
try {
secretKeyRingCollection = PGPainless.readKeyRing().secretKeyRingCollection(inputStream);
secretKeyRingCollection = KeyReader.readSecretKeys(inputStream, true);
} catch (IOException e) {
throw new SOPGPException.BadData(e);
}

View file

@ -105,11 +105,7 @@ public class EncryptImpl implements Encrypt {
@Override
public Encrypt withCert(InputStream cert) throws SOPGPException.CertCannotEncrypt, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData {
try {
PGPPublicKeyRingCollection certificates = PGPainless.readKeyRing()
.publicKeyRingCollection(cert);
if (certificates.size() == 0) {
throw new SOPGPException.BadData("No certificate data found.");
}
PGPPublicKeyRingCollection certificates = KeyReader.readPublicKeys(cert, true);
encryptionOptions.addRecipients(certificates);
} catch (KeyException.UnacceptableEncryptionKeyException e) {
throw new SOPGPException.CertCannotEncrypt(e.getMessage(), e);

View file

@ -66,7 +66,7 @@ public class RevokeKeyImpl implements RevokeKey {
public Ready keys(InputStream keys) throws SOPGPException.BadData {
PGPSecretKeyRingCollection secretKeyRings;
try {
secretKeyRings = PGPainless.readKeyRing().secretKeyRingCollection(keys);
secretKeyRings = KeyReader.readSecretKeys(keys, true);
} catch (IOException e) {
throw new SOPGPException.BadData("Cannot decode secret keys.", e);
}