1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 04:42:06 +01:00

Add reader methods for key ring

This commit is contained in:
Paul Schaub 2018-07-12 23:12:45 +02:00
parent 4b4126e45c
commit 71f196afe8
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -27,6 +27,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
import org.pgpainless.pgpainless.key.collection.PGPKeyRing;
public class KeyRingReader {
@ -82,6 +83,24 @@ public class KeyRingReader {
return secretKeyRingCollection(asciiArmored.getBytes(UTF8));
}
public PGPKeyRing keyRing(InputStream publicIn, InputStream secretIn) throws IOException, PGPException {
return readKeyRing(publicIn, secretIn);
}
public PGPKeyRing keyRing(byte[] publicBytes, byte[] secretBytes) throws IOException, PGPException {
return keyRing(
publicBytes != null ? new ByteArrayInputStream(publicBytes) : null,
secretBytes != null ? new ByteArrayInputStream(secretBytes) : null
);
}
public PGPKeyRing keyRing(String asciiPublic, String asciiSecret) throws IOException, PGPException {
return keyRing(
asciiPublic != null ? asciiPublic.getBytes(UTF8) : null,
asciiSecret != null ? asciiSecret.getBytes(UTF8) : null
);
}
/*
STATIC METHODS
*/
@ -111,4 +130,16 @@ public class KeyRingReader {
PGPUtil.getDecoderStream(inputStream),
new BcKeyFingerprintCalculator());
}
public static PGPKeyRing readKeyRing(InputStream publicIn, InputStream secretIn) throws IOException, PGPException {
PGPPublicKeyRing publicKeys = null;
if (publicIn != null) {
publicKeys = readPublicKeyRing(publicIn);
}
PGPSecretKeyRing secretKeys = null;
if (secretIn != null) {
secretKeys = readSecretKeyRing(secretIn);
}
return new PGPKeyRing(publicKeys, secretKeys);
}
}