mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-06 20:31:08 +01: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
8b8bd798a3
commit
4646f4319b
3 changed files with 18 additions and 107 deletions
|
|
@ -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