diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/PGPainless.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/PGPainless.kt index fc3b182b..190d926e 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/PGPainless.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/PGPainless.kt @@ -60,6 +60,16 @@ class PGPainless( implementation, version.numeric, version == OpenPGPKeyVersion.v6, creationTime) .setAlgorithmSuite(algorithmPolicy.keyGenerationAlgorithmSuite) + /** + * Inspect an [OpenPGPKey] or [OpenPGPCertificate], gaining convenient access to its properties. + * + * @param keyOrCertificate [OpenPGPKey] or [OpenPGPCertificate] + * @param referenceTime reference time for evaluation + * @return [KeyRingInfo] wrapper + */ + fun inspect(keyOrCertificate: OpenPGPCertificate, referenceTime: Date = Date()): KeyRingInfo = + KeyRingInfo(keyOrCertificate, this, referenceTime) + fun readKey(): OpenPGPKeyReader = api.readKeyOrCertificate() fun toKey(secretKeyRing: PGPSecretKeyRing): OpenPGPKey = @@ -118,6 +128,7 @@ class PGPainless( */ @JvmStatic @JvmOverloads + @Deprecated("Call buildKey() on an instance of PGPainless instead.") fun buildKeyRing( version: OpenPGPKeyVersion = OpenPGPKeyVersion.v4, api: PGPainless = getInstance() @@ -128,8 +139,8 @@ class PGPainless( * * @return builder */ - @Deprecated("Use readKey() instead.", replaceWith = ReplaceWith("readKey()")) @JvmStatic + @Deprecated("Use readKey() instead.", replaceWith = ReplaceWith("readKey()")) fun readKeyRing(): KeyRingReader = KeyRingReader() /** @@ -250,11 +261,17 @@ class PGPainless( */ @JvmStatic @JvmOverloads + @Deprecated( + "Use inspect(key) on an instance of PGPainless instead.", + replaceWith = ReplaceWith("inspect(key)")) fun inspectKeyRing(key: PGPKeyRing, referenceTime: Date = Date()): KeyRingInfo = KeyRingInfo(key, referenceTime) @JvmStatic @JvmOverloads + @Deprecated( + "Use inspect(key) on an instance of PGPainless instead.", + replaceWith = ReplaceWith("inspect(key)")) fun inspectKeyRing(key: OpenPGPCertificate, referenceTime: Date = Date()): KeyRingInfo = KeyRingInfo(key, getInstance(), referenceTime) diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/parsing/KeyRingReaderTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/parsing/KeyRingReaderTest.java index 9bda5137..7bfffe92 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/parsing/KeyRingReaderTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/parsing/KeyRingReaderTest.java @@ -21,6 +21,7 @@ import java.util.List; import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.bcpg.BCPGOutputStream; import org.bouncycastle.bcpg.MarkerPacket; +import org.bouncycastle.bcpg.PacketFormat; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRing; @@ -30,6 +31,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPUtil; import org.bouncycastle.openpgp.api.OpenPGPImplementation; +import org.bouncycastle.openpgp.api.OpenPGPKey; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.api.Test; import org.opentest4j.TestAbortedException; @@ -614,9 +616,10 @@ class KeyRingReaderTest { @Test public void testReadKeyRingWithArmoredSecretKey() throws IOException { - PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice ") - .getPGPSecretKeyRing(); - String armored = PGPainless.asciiArmor(secretKeys); + PGPainless api = PGPainless.getInstance(); + OpenPGPKey secretKeys = api.generateKey().modernKeyRing("Alice "); + // remove PacketFormat argument once https://github.com/bcgit/bc-java/pull/1993 lands in BC + String armored = secretKeys.toAsciiArmoredString(PacketFormat.LEGACY); PGPKeyRing keyRing = PGPainless.readKeyRing() .keyRing(armored);