From 4cc8054cff926022e4d94da249096af675325d6c Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 6 Jul 2023 13:08:56 +0200 Subject: [PATCH] KeyRingReader.readPublicKeyRingCollection: Handle secret keys as public keys --- .../java/org/pgpainless/key/parsing/KeyRingReader.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java b/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java index 6d67793b..7a06f955 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java @@ -23,6 +23,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.util.io.Streams; +import org.pgpainless.PGPainless; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.collection.PGPKeyRingCollection; import org.pgpainless.util.ArmorUtils; @@ -295,6 +296,12 @@ public class KeyRingReader { } if (next instanceof PGPPublicKeyRing) { rings.add((PGPPublicKeyRing) next); + continue; + } + // Parse public keys from secret keys + if (next instanceof PGPSecretKeyRing) { + rings.add(PGPainless.extractCertificate((PGPSecretKeyRing) next)); + continue; } if (next instanceof PGPPublicKeyRingCollection) { PGPPublicKeyRingCollection collection = (PGPPublicKeyRingCollection) next;