1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 10:19:39 +02:00

Add more deprecation annotations, workaround for BC armor bug

This commit is contained in:
Paul Schaub 2025-03-19 14:26:25 +01:00
parent 74c821c1e8
commit 2a71a98bba
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 24 additions and 4 deletions

View file

@ -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)

View file

@ -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 <alice@pgpainless.org>")
.getPGPSecretKeyRing();
String armored = PGPainless.asciiArmor(secretKeys);
PGPainless api = PGPainless.getInstance();
OpenPGPKey secretKeys = api.generateKey().modernKeyRing("Alice <alice@pgpainless.org>");
// 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);