mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Remove deprecated KeyInfo class
If you relied on it, replace its usage with the Kotlin extension functions as documented. If you are using Java, use static methods from PGPPublicKeyExtensionsKt and PGPSecretKeyExtensionsKt instead.
This commit is contained in:
parent
93ee037ef0
commit
77890cc933
3 changed files with 18 additions and 107 deletions
|
@ -1,81 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>, 2021 Flowcrypt a.s.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.key.info
|
||||
|
||||
import org.bouncycastle.openpgp.PGPPublicKey
|
||||
import org.bouncycastle.openpgp.PGPSecretKey
|
||||
import org.pgpainless.bouncycastle.extensions.getCurveName
|
||||
import org.pgpainless.bouncycastle.extensions.hasDummyS2K
|
||||
import org.pgpainless.bouncycastle.extensions.isDecrypted
|
||||
import org.pgpainless.bouncycastle.extensions.isEncrypted
|
||||
|
||||
@Deprecated("Deprecated in favor of extension functions to PGPSecretKey and PGPPublicKey.")
|
||||
class KeyInfo private constructor(val secretKey: PGPSecretKey?, val publicKey: PGPPublicKey) {
|
||||
|
||||
constructor(secretKey: PGPSecretKey) : this(secretKey, secretKey.publicKey)
|
||||
|
||||
constructor(publicKey: PGPPublicKey) : this(null, publicKey)
|
||||
|
||||
/**
|
||||
* Return the name of the elliptic curve used by this key, or throw an
|
||||
* [IllegalArgumentException] if the key is not based on elliptic curves, or on an unknown
|
||||
* curve.
|
||||
*/
|
||||
@Deprecated(
|
||||
"Deprecated in favor of calling getCurveName() on the PGPPublicKey itself.",
|
||||
ReplaceWith("publicKey.getCurveName()"))
|
||||
val curveName: String
|
||||
get() = publicKey.getCurveName()
|
||||
|
||||
/**
|
||||
* Return true, if the secret key is encrypted. This method returns false, if the secret key is
|
||||
* null.
|
||||
*/
|
||||
@Deprecated(
|
||||
"Deprecated in favor of calling isEncrypted() on the PGPSecretKey itself.",
|
||||
ReplaceWith("secretKey.isEncrypted()"))
|
||||
val isEncrypted: Boolean
|
||||
get() = secretKey?.isEncrypted() ?: false
|
||||
|
||||
/**
|
||||
* Return true, if the secret key is decrypted. This method returns true, if the secret key is
|
||||
* null.
|
||||
*/
|
||||
@Deprecated(
|
||||
"Deprecated in favor of calling isDecrypted() on the PGPSecretKey itself.",
|
||||
ReplaceWith("secretKey.isDecrypted()"))
|
||||
val isDecrypted: Boolean
|
||||
get() = secretKey?.isDecrypted() ?: true
|
||||
|
||||
/**
|
||||
* Return true, if the secret key is using the GNU_DUMMY_S2K s2k type. This method returns
|
||||
* false, if the secret key is null.
|
||||
*/
|
||||
@Deprecated(
|
||||
"Deprecated in favor of calling hasDummyS2K() on the PGPSecretKey itself.",
|
||||
ReplaceWith("secretKey.hasDummyS2K()"))
|
||||
val hasDummyS2K: Boolean
|
||||
@JvmName("hasDummyS2K") get() = secretKey?.hasDummyS2K() ?: false
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@Deprecated(
|
||||
"Deprecated in favor of calling isEncrypted() on the PGPSecretKey itself.",
|
||||
ReplaceWith("secretKey.isEncrypted()"))
|
||||
fun isEncrypted(secretKey: PGPSecretKey?) = secretKey.isEncrypted()
|
||||
|
||||
@JvmStatic
|
||||
@Deprecated(
|
||||
"Deprecated in favor of calling isDecrypted() on the PGPSecretKey itself.",
|
||||
ReplaceWith("secretKey.isDecrypted()"))
|
||||
fun isDecrypted(secretKey: PGPSecretKey?) = secretKey.isDecrypted()
|
||||
|
||||
@JvmStatic
|
||||
@Deprecated(
|
||||
"Deprecated in favor of calling hasDummyS2K() on the PGPSecretKey itself.",
|
||||
ReplaceWith("secretKey.hasDummyS2K()"))
|
||||
fun hasDummyS2K(secretKey: PGPSecretKey?) = secretKey.hasDummyS2K()
|
||||
}
|
||||
}
|
|
@ -11,7 +11,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
|
@ -19,12 +18,13 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
import org.pgpainless.bouncycastle.extensions.PGPPublicKeyExtensionsKt;
|
||||
import org.pgpainless.bouncycastle.extensions.PGPSecretKeyExtensionsKt;
|
||||
import org.pgpainless.key.generation.type.KeyType;
|
||||
import org.pgpainless.key.generation.type.ecc.EllipticCurve;
|
||||
import org.pgpainless.key.generation.type.eddsa_legacy.EdDSALegacyCurve;
|
||||
import org.pgpainless.key.generation.type.rsa.RsaLength;
|
||||
import org.pgpainless.key.generation.type.xdh_legacy.XDHLegacySpec;
|
||||
import org.pgpainless.key.info.KeyInfo;
|
||||
import org.pgpainless.key.util.UserId;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
import org.pgpainless.util.TestAllImplementations;
|
||||
|
@ -47,15 +47,13 @@ public class BrainpoolKeyGenerationTest {
|
|||
Iterator<PGPSecretKey> secretKeyIterator = secretKeys.iterator();
|
||||
|
||||
PGPSecretKey primaryKey = secretKeyIterator.next();
|
||||
KeyInfo primaryInfo = new KeyInfo(primaryKey);
|
||||
assertEquals(curve.getName(), primaryInfo.getCurveName());
|
||||
assertFalse(primaryInfo.isEncrypted());
|
||||
assertTrue(primaryInfo.isDecrypted());
|
||||
assertFalse(primaryInfo.hasDummyS2K());
|
||||
assertEquals(curve.getName(), PGPPublicKeyExtensionsKt.getCurveName(primaryKey.getPublicKey()));
|
||||
assertFalse(PGPSecretKeyExtensionsKt.isEncrypted(primaryKey));
|
||||
assertTrue(PGPSecretKeyExtensionsKt.isDecrypted(primaryKey));
|
||||
assertFalse(PGPSecretKeyExtensionsKt.hasDummyS2K(primaryKey));
|
||||
|
||||
PGPSecretKey subKey = secretKeyIterator.next();
|
||||
KeyInfo subInfo = new KeyInfo(subKey);
|
||||
assertEquals(curve.getName(), subInfo.getCurveName());
|
||||
assertEquals(curve.getName(), PGPPublicKeyExtensionsKt.getCurveName(subKey.getPublicKey()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,35 +75,28 @@ public class BrainpoolKeyGenerationTest {
|
|||
.getPGPSecretKeyRing();
|
||||
|
||||
for (PGPSecretKey key : secretKeys) {
|
||||
KeyInfo info = new KeyInfo(key);
|
||||
assertTrue(info.isEncrypted());
|
||||
assertFalse(info.isDecrypted());
|
||||
|
||||
PGPPublicKey pubKey = key.getPublicKey();
|
||||
assertFalse(new KeyInfo(pubKey).isEncrypted());
|
||||
assertTrue(new KeyInfo(pubKey).isDecrypted());
|
||||
assertFalse(new KeyInfo(pubKey).hasDummyS2K());
|
||||
assertTrue(PGPSecretKeyExtensionsKt.isEncrypted(key));
|
||||
assertFalse(PGPSecretKeyExtensionsKt.isDecrypted(key));
|
||||
assertFalse(PGPSecretKeyExtensionsKt.hasDummyS2K(key));
|
||||
}
|
||||
|
||||
Iterator<PGPSecretKey> iterator = secretKeys.iterator();
|
||||
PGPSecretKey ecdsaPrim = iterator.next();
|
||||
KeyInfo ecdsaInfo = new KeyInfo(ecdsaPrim);
|
||||
assertEquals(EllipticCurve._BRAINPOOLP384R1.getName(), ecdsaInfo.getCurveName());
|
||||
assertEquals(EllipticCurve._BRAINPOOLP384R1.getName(), PGPPublicKeyExtensionsKt.getCurveName(ecdsaPrim.getPublicKey()));
|
||||
assertEquals(384, ecdsaPrim.getPublicKey().getBitStrength());
|
||||
|
||||
PGPSecretKey eddsaSub = iterator.next();
|
||||
KeyInfo eddsaInfo = new KeyInfo(eddsaSub);
|
||||
assertEquals(EdDSALegacyCurve._Ed25519.getName(), eddsaInfo.getCurveName());
|
||||
assertEquals(EdDSALegacyCurve._Ed25519.getName(), PGPPublicKeyExtensionsKt.getCurveName(eddsaSub.getPublicKey()));
|
||||
assertEquals(256, eddsaSub.getPublicKey().getBitStrength());
|
||||
|
||||
PGPSecretKey xdhSub = iterator.next();
|
||||
KeyInfo xdhInfo = new KeyInfo(xdhSub);
|
||||
assertEquals(XDHLegacySpec._X25519.getCurveName(), xdhInfo.getCurveName());
|
||||
assertEquals(XDHLegacySpec._X25519.getCurveName(), PGPPublicKeyExtensionsKt.getCurveName(xdhSub.getPublicKey()));
|
||||
assertEquals(256, xdhSub.getPublicKey().getBitStrength());
|
||||
|
||||
PGPSecretKey rsaSub = iterator.next();
|
||||
KeyInfo rsaInfo = new KeyInfo(rsaSub);
|
||||
assertThrows(IllegalArgumentException.class, rsaInfo::getCurveName, "RSA is not a curve-based encryption system");
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> PGPPublicKeyExtensionsKt.getCurveName(rsaSub.getPublicKey()),
|
||||
"RSA is not a curve-based encryption system");
|
||||
assertEquals(3072, rsaSub.getPublicKey().getBitStrength());
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.pgpainless.algorithm.KeyFlag;
|
|||
import org.pgpainless.algorithm.OpenPGPKeyVersion;
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.bouncycastle.extensions.PGPSecretKeyExtensionsKt;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
import org.pgpainless.key.generation.KeySpec;
|
||||
|
@ -217,7 +218,7 @@ public class KeyRingInfoTest {
|
|||
"-----END PGP PRIVATE KEY BLOCK-----\n";
|
||||
|
||||
OpenPGPKey secretKeys = PGPainless.getInstance().readKey().parseKey(withDummyS2K);
|
||||
assertTrue(new KeyInfo(secretKeys.getPrimarySecretKey().getPGPSecretKey()).hasDummyS2K());
|
||||
assertTrue(PGPSecretKeyExtensionsKt.hasDummyS2K(secretKeys.getPrimarySecretKey().getPGPSecretKey()));
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue