From 23781629534b19b18ebf5caa879cd46ff8eb88f2 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 3 Jan 2021 16:26:53 +0100 Subject: [PATCH] Remove withDefaultKeyFlags method --- .../org/pgpainless/key/generation/KeyRingBuilder.java | 2 +- .../org/pgpainless/key/generation/KeySpecBuilder.java | 10 ---------- .../key/generation/KeySpecBuilderInterface.java | 2 -- .../CertificationKeyMustBeAbleToCertifyTest.java | 3 ++- .../key/generation/GenerateEllipticCurveKeyTest.java | 5 +++-- .../GenerateKeyWithAdditionalUserIdTest.java | 3 ++- .../key/generation/GenerateWithEmptyPassphrase.java | 3 ++- .../src/test/java/org/pgpainless/util/BCUtilTest.java | 9 +++++++-- 8 files changed, 17 insertions(+), 20 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java index f446383f..d1a4db28 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java @@ -103,7 +103,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface { WithAdditionalUserIdOrPassphrase builder = this .withMasterKey( KeySpec.getBuilder(KeyType.RSA(length)) - .withDefaultKeyFlags() + .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS) .withDefaultAlgorithms()) .withPrimaryUserId(userId); diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeySpecBuilder.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeySpecBuilder.java index fe67ade8..5e212ed2 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeySpecBuilder.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeySpecBuilder.java @@ -42,16 +42,6 @@ public class KeySpecBuilder implements KeySpecBuilderInterface { return new WithDetailedConfigurationImpl(); } - @Override - public WithDetailedConfiguration withDefaultKeyFlags() { - return withKeyFlags( - KeyFlag.CERTIFY_OTHER, - KeyFlag.SIGN_DATA, - KeyFlag.ENCRYPT_COMMS, - KeyFlag.ENCRYPT_STORAGE, - KeyFlag.AUTHENTICATION); - } - @Override public KeySpec withInheritedSubPackets() { return new KeySpec(type, null, true); diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeySpecBuilderInterface.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeySpecBuilderInterface.java index 310abf82..f16959fd 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeySpecBuilderInterface.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeySpecBuilderInterface.java @@ -27,8 +27,6 @@ public interface KeySpecBuilderInterface { WithDetailedConfiguration withKeyFlags(@Nonnull KeyFlag... flags); - WithDetailedConfiguration withDefaultKeyFlags(); - KeySpec withInheritedSubPackets(); interface WithDetailedConfiguration { diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java index 1bde8f16..960ae754 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; import org.pgpainless.PGPainless; +import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.ecc.EllipticCurve; import org.pgpainless.key.generation.type.xdh.XDHCurve; @@ -43,7 +44,7 @@ public class CertificationKeyMustBeAbleToCertifyTest { .generateKeyRing() .withMasterKey(KeySpec .getBuilder(type) - .withDefaultKeyFlags() + .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) .withDefaultAlgorithms()) .withPrimaryUserId("should@throw.ex") .withoutPassphrase().build()); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java index bad8eaeb..cae2bd0a 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java @@ -23,6 +23,7 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.jupiter.api.Test; import org.pgpainless.PGPainless; +import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.eddsa.EdDSACurve; import org.pgpainless.key.generation.type.xdh.XDHCurve; @@ -35,10 +36,10 @@ public class GenerateEllipticCurveKeyTest { public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { PGPSecretKeyRing keyRing = PGPainless.generateKeyRing() .withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) - .withDefaultKeyFlags() + .withKeyFlags(KeyFlag.ENCRYPT_COMMS) .withDefaultAlgorithms()) .withMasterKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) - .withDefaultKeyFlags() + .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) .withDefaultAlgorithms()) .withPrimaryUserId(UserId.onlyEmail("alice@wonderland.lit").toString()) .withoutPassphrase() diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java index 2aca9b5a..e2588231 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java @@ -30,6 +30,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.jupiter.api.Test; import org.pgpainless.PGPainless; +import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.key.util.KeyRingUtils; @@ -40,7 +41,7 @@ public class GenerateKeyWithAdditionalUserIdTest { public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() .withMasterKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) - .withDefaultKeyFlags() + .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS) .withDefaultAlgorithms()) .withPrimaryUserId("primary@user.id") .withAdditionalUserId("additional@user.id") diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java index 305bd734..56345c5a 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java @@ -24,6 +24,7 @@ import java.security.NoSuchAlgorithmException; import org.bouncycastle.openpgp.PGPException; import org.junit.jupiter.api.Test; import org.pgpainless.PGPainless; +import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.util.Passphrase; @@ -41,7 +42,7 @@ public class GenerateWithEmptyPassphrase { public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { assertNotNull(PGPainless.generateKeyRing() .withMasterKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) - .withDefaultKeyFlags() + .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS) .withDefaultAlgorithms()) .withPrimaryUserId("primary@user.id") .withPassphrase(Passphrase.emptyPassphrase()) diff --git a/pgpainless-core/src/test/java/org/pgpainless/util/BCUtilTest.java b/pgpainless-core/src/test/java/org/pgpainless/util/BCUtilTest.java index 57f079ee..3db27b64 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/util/BCUtilTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/util/BCUtilTest.java @@ -35,6 +35,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.junit.jupiter.api.Test; import org.pgpainless.PGPainless; +import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.key.generation.KeySpec; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.rsa.RsaLength; @@ -49,8 +50,12 @@ public class BCUtilTest { throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { PGPSecretKeyRing sec = PGPainless.generateKeyRing() - .withSubKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)).withDefaultKeyFlags().withDefaultAlgorithms()) - .withMasterKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)).withDefaultKeyFlags().withDefaultAlgorithms()) + .withSubKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) + .withKeyFlags(KeyFlag.ENCRYPT_COMMS) + .withDefaultAlgorithms()) + .withMasterKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) + .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) + .withDefaultAlgorithms()) .withPrimaryUserId("donald@duck.tails").withoutPassphrase().build(); PGPPublicKeyRing pub = KeyRingUtils.publicKeyRingFrom(sec);