From 7a777ab91492f4c6ad32f57b459a2e40823d8c7b 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;