1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-13 15:15:04 +02:00

Add KeyRingUtils.publicKeyRingCollectionFrom(PGPSecretKeyRingCollection)

This commit is contained in:
Paul Schaub 2022-07-15 13:21:59 +02:00
parent 2ad67a85fb
commit 32e1f1234b
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -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<PGPPublicKeyRing> 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}.
*