mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-18 02:12:06 +01:00
Use KeyReader class when reading public or secret keys
This commit is contained in:
parent
744c679e0c
commit
e5539a810d
3 changed files with 3 additions and 8 deletions
|
@ -14,7 +14,6 @@ import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||||
import org.pgpainless.PGPainless;
|
|
||||||
import org.pgpainless.exception.MissingPassphraseException;
|
import org.pgpainless.exception.MissingPassphraseException;
|
||||||
import org.pgpainless.key.OpenPgpFingerprint;
|
import org.pgpainless.key.OpenPgpFingerprint;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
|
@ -54,7 +53,7 @@ public class ChangeKeyPasswordImpl implements ChangeKeyPassword {
|
||||||
SecretKeyRingProtector newProtector = SecretKeyRingProtector.unlockAnyKeyWith(newPassphrase);
|
SecretKeyRingProtector newProtector = SecretKeyRingProtector.unlockAnyKeyWith(newPassphrase);
|
||||||
PGPSecretKeyRingCollection secretKeyRingCollection;
|
PGPSecretKeyRingCollection secretKeyRingCollection;
|
||||||
try {
|
try {
|
||||||
secretKeyRingCollection = PGPainless.readKeyRing().secretKeyRingCollection(inputStream);
|
secretKeyRingCollection = KeyReader.readSecretKeys(inputStream, true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SOPGPException.BadData(e);
|
throw new SOPGPException.BadData(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,11 +105,7 @@ public class EncryptImpl implements Encrypt {
|
||||||
@Override
|
@Override
|
||||||
public Encrypt withCert(InputStream cert) throws SOPGPException.CertCannotEncrypt, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData {
|
public Encrypt withCert(InputStream cert) throws SOPGPException.CertCannotEncrypt, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData {
|
||||||
try {
|
try {
|
||||||
PGPPublicKeyRingCollection certificates = PGPainless.readKeyRing()
|
PGPPublicKeyRingCollection certificates = KeyReader.readPublicKeys(cert, true);
|
||||||
.publicKeyRingCollection(cert);
|
|
||||||
if (certificates.size() == 0) {
|
|
||||||
throw new SOPGPException.BadData("No certificate data found.");
|
|
||||||
}
|
|
||||||
encryptionOptions.addRecipients(certificates);
|
encryptionOptions.addRecipients(certificates);
|
||||||
} catch (KeyException.UnacceptableEncryptionKeyException e) {
|
} catch (KeyException.UnacceptableEncryptionKeyException e) {
|
||||||
throw new SOPGPException.CertCannotEncrypt(e.getMessage(), e);
|
throw new SOPGPException.CertCannotEncrypt(e.getMessage(), e);
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class RevokeKeyImpl implements RevokeKey {
|
||||||
public Ready keys(InputStream keys) throws SOPGPException.BadData {
|
public Ready keys(InputStream keys) throws SOPGPException.BadData {
|
||||||
PGPSecretKeyRingCollection secretKeyRings;
|
PGPSecretKeyRingCollection secretKeyRings;
|
||||||
try {
|
try {
|
||||||
secretKeyRings = PGPainless.readKeyRing().secretKeyRingCollection(keys);
|
secretKeyRings = KeyReader.readSecretKeys(keys, true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SOPGPException.BadData("Cannot decode secret keys.", e);
|
throw new SOPGPException.BadData("Cannot decode secret keys.", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue