diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyRingUtils.java b/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyRingUtils.java index 21c5b575..66536b88 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyRingUtils.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyRingUtils.java @@ -161,6 +161,25 @@ public final class KeyRingUtils { return publicKeyRing; } + /** + * Extract {@link PGPPublicKeyRing PGPPublicKeyRings} from all {@link PGPSecretKeyRing PGPSecretKeyRings} in + * the given {@link PGPSecretKeyRingCollection} and return them as a {@link PGPPublicKeyRingCollection}. + * + * @param secretKeyRings secret key ring collection + * @return public key ring collection + * @throws PGPException TODO: remove + * @throws IOException TODO: remove + */ + @Nonnull + public static PGPPublicKeyRingCollection publicKeyRingCollectionFrom(@Nonnull PGPSecretKeyRingCollection secretKeyRings) + throws PGPException, IOException { + List certificates = new ArrayList<>(); + for (PGPSecretKeyRing secretKey : secretKeyRings) { + certificates.add(PGPainless.extractCertificate(secretKey)); + } + return new PGPPublicKeyRingCollection(certificates); + } + /** * Unlock a {@link PGPSecretKey} and return the resulting {@link PGPPrivateKey}. *