From 71f196afe8671b61a19a5f034b675fb6d6d0296a Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 12 Jul 2018 23:12:45 +0200 Subject: [PATCH] Add reader methods for key ring --- .../pgpainless/key/parsing/KeyRingReader.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/org/pgpainless/pgpainless/key/parsing/KeyRingReader.java b/src/main/java/org/pgpainless/pgpainless/key/parsing/KeyRingReader.java index 37d2f18d..51888e98 100644 --- a/src/main/java/org/pgpainless/pgpainless/key/parsing/KeyRingReader.java +++ b/src/main/java/org/pgpainless/pgpainless/key/parsing/KeyRingReader.java @@ -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); + } }