From 65474cd81e22efa820a24bb4ecb588866f1b0781 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 12 Jun 2024 11:56:45 +0200 Subject: [PATCH] Fix checkstyle issues in test classes --- .../Curve25519PrivateKeyEncodingTest.java | 15 +++++++--- .../test/DedicatedEd25519KeyPairTest.java | 29 +++++++++++++++---- .../test/DedicatedEd448KeyPairTest.java | 6 +++- .../test/DedicatedX25519KeyPairTest.java | 24 ++++++++++++--- .../test/DedicatedX448KeyPairTest.java | 24 ++++++++++++--- .../test/LegacyEd25519KeyPairTest.java | 6 +++- .../openpgp/test/LegacyX25519KeyPairTest.java | 24 ++++++++++++--- .../openpgp/test/LegacyX448KeyPairTest.java | 10 +++++-- 8 files changed, 113 insertions(+), 25 deletions(-) diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/Curve25519PrivateKeyEncodingTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/Curve25519PrivateKeyEncodingTest.java index 96ecc77a44..9e8942ed7a 100644 --- a/pg/src/test/java/org/bouncycastle/openpgp/test/Curve25519PrivateKeyEncodingTest.java +++ b/pg/src/test/java/org/bouncycastle/openpgp/test/Curve25519PrivateKeyEncodingTest.java @@ -2,14 +2,15 @@ import org.bouncycastle.asn1.ASN1OctetString; import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; -import org.bouncycastle.bcpg.*; +import org.bouncycastle.bcpg.PublicKeyAlgorithmTags; import org.bouncycastle.crypto.AsymmetricCipherKeyPair; import org.bouncycastle.crypto.generators.X25519KeyPairGenerator; import org.bouncycastle.crypto.params.X25519KeyGenerationParameters; import org.bouncycastle.crypto.params.X25519PrivateKeyParameters; import org.bouncycastle.jcajce.spec.XDHParameterSpec; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.openpgp.*; +import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPKeyPair; import org.bouncycastle.openpgp.operator.bc.BcPGPKeyConverter; import org.bouncycastle.openpgp.operator.bc.BcPGPKeyPair; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; @@ -17,7 +18,12 @@ import org.bouncycastle.util.Arrays; import java.io.IOException; -import java.security.*; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.SecureRandom; import java.util.Date; /** @@ -169,7 +175,8 @@ public boolean containsSubsequence(byte[] sequence, byte[] subsequence) /** * Test proper functionality of the {@link #containsSubsequence(byte[], byte[])} method. */ - private void containsTest() { + private void containsTest() + { // Make sure our containsSubsequence method functions correctly byte[] s = new byte[] {0x00, 0x01, 0x02, 0x03}; isTrue(containsSubsequence(s, new byte[] {0x00, 0x01})); diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedEd25519KeyPairTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedEd25519KeyPairTest.java index e8ff3b0ccc..7ff616c852 100644 --- a/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedEd25519KeyPairTest.java +++ b/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedEd25519KeyPairTest.java @@ -1,16 +1,28 @@ package org.bouncycastle.openpgp.test; -import org.bouncycastle.bcpg.*; +import org.bouncycastle.bcpg.Ed25519PublicBCPGKey; +import org.bouncycastle.bcpg.Ed25519SecretBCPGKey; +import org.bouncycastle.bcpg.HashAlgorithmTags; +import org.bouncycastle.bcpg.PublicKeyAlgorithmTags; +import org.bouncycastle.bcpg.PublicKeyPacket; import org.bouncycastle.crypto.AsymmetricCipherKeyPair; import org.bouncycastle.crypto.generators.Ed25519KeyPairGenerator; import org.bouncycastle.crypto.params.AsymmetricKeyParameter; import org.bouncycastle.crypto.params.Ed25519KeyGenerationParameters; import org.bouncycastle.jcajce.spec.EdDSAParameterSpec; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.openpgp.*; +import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPKeyPair; +import org.bouncycastle.openpgp.PGPPublicKey; +import org.bouncycastle.openpgp.PGPSignature; +import org.bouncycastle.openpgp.PGPSignatureGenerator; import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder; import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider; -import org.bouncycastle.openpgp.operator.bc.*; +import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; +import org.bouncycastle.openpgp.operator.bc.BcPGPContentSignerBuilder; +import org.bouncycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider; +import org.bouncycastle.openpgp.operator.bc.BcPGPKeyConverter; +import org.bouncycastle.openpgp.operator.bc.BcPGPKeyPair; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; @@ -20,7 +32,12 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.security.*; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.PublicKey; +import java.security.SecureRandom; import java.util.Date; public class DedicatedEd25519KeyPairTest @@ -184,7 +201,9 @@ private void testConversionOfBcKeyPair() date.getTime(), j2.getPublicKey().getCreationTime().getTime()); } - private void testConversionOfTestVectorKey() throws PGPException, IOException { + private void testConversionOfTestVectorKey() + throws PGPException, IOException + { JcaPGPKeyConverter jc = new JcaPGPKeyConverter().setProvider(new BouncyCastleProvider()); BcPGPKeyConverter bc = new BcPGPKeyConverter(); // ed25519 public key from https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-13.html#name-hashed-data-stream-for-sign diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedEd448KeyPairTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedEd448KeyPairTest.java index 3864f3f8db..baa3560cf9 100644 --- a/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedEd448KeyPairTest.java +++ b/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedEd448KeyPairTest.java @@ -24,7 +24,11 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.security.*; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.Date; public class DedicatedEd448KeyPairTest diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedX25519KeyPairTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedX25519KeyPairTest.java index d5f64817f4..0b2fcc99fa 100644 --- a/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedX25519KeyPairTest.java +++ b/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedX25519KeyPairTest.java @@ -9,7 +9,14 @@ import org.bouncycastle.crypto.params.X25519KeyGenerationParameters; import org.bouncycastle.jcajce.spec.XDHParameterSpec; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.openpgp.*; +import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; +import org.bouncycastle.openpgp.PGPEncryptedDataList; +import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPKeyPair; +import org.bouncycastle.openpgp.PGPLiteralData; +import org.bouncycastle.openpgp.PGPLiteralDataGenerator; +import org.bouncycastle.openpgp.PGPObjectFactory; +import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData; import org.bouncycastle.openpgp.bc.BcPGPObjectFactory; import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; import org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder; @@ -26,9 +33,17 @@ import org.bouncycastle.util.Arrays; import org.bouncycastle.util.io.Streams; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.charset.StandardCharsets; -import java.security.*; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.Date; public class DedicatedX25519KeyPairTest @@ -100,7 +115,8 @@ private void testV4MessageEncryptionDecryptionWithJcaKey() } private void testV4MessageEncryptionDecryptionWithBcKey() - throws PGPException, IOException { + throws PGPException, IOException + { Date date = currentTimeRounded(); X25519KeyPairGenerator gen = new X25519KeyPairGenerator(); gen.init(new X25519KeyGenerationParameters(new SecureRandom())); diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedX448KeyPairTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedX448KeyPairTest.java index 334d1add96..758a069c08 100644 --- a/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedX448KeyPairTest.java +++ b/pg/src/test/java/org/bouncycastle/openpgp/test/DedicatedX448KeyPairTest.java @@ -9,7 +9,14 @@ import org.bouncycastle.crypto.params.X448KeyGenerationParameters; import org.bouncycastle.jcajce.spec.XDHParameterSpec; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.openpgp.*; +import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; +import org.bouncycastle.openpgp.PGPEncryptedDataList; +import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPKeyPair; +import org.bouncycastle.openpgp.PGPLiteralData; +import org.bouncycastle.openpgp.PGPLiteralDataGenerator; +import org.bouncycastle.openpgp.PGPObjectFactory; +import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData; import org.bouncycastle.openpgp.bc.BcPGPObjectFactory; import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; import org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder; @@ -26,9 +33,17 @@ import org.bouncycastle.util.Arrays; import org.bouncycastle.util.io.Streams; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.charset.StandardCharsets; -import java.security.*; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.Date; public class DedicatedX448KeyPairTest @@ -100,7 +115,8 @@ private void testV4MessageEncryptionDecryptionWithJcaKey() } private void testV4MessageEncryptionDecryptionWithBcKey() - throws PGPException, IOException { + throws PGPException, IOException + { Date date = currentTimeRounded(); X448KeyPairGenerator gen = new X448KeyPairGenerator(); gen.init(new X448KeyGenerationParameters(new SecureRandom())); diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyEd25519KeyPairTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyEd25519KeyPairTest.java index f3efe8bc1e..b24a934db0 100644 --- a/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyEd25519KeyPairTest.java +++ b/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyEd25519KeyPairTest.java @@ -24,7 +24,11 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.security.*; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.Date; public class LegacyEd25519KeyPairTest diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyX25519KeyPairTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyX25519KeyPairTest.java index 66a1c195f4..f58d08b211 100644 --- a/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyX25519KeyPairTest.java +++ b/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyX25519KeyPairTest.java @@ -9,7 +9,14 @@ import org.bouncycastle.crypto.params.X25519KeyGenerationParameters; import org.bouncycastle.jcajce.spec.XDHParameterSpec; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.openpgp.*; +import org.bouncycastle.openpgp.PGPEncryptedDataGenerator; +import org.bouncycastle.openpgp.PGPEncryptedDataList; +import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPKeyPair; +import org.bouncycastle.openpgp.PGPLiteralData; +import org.bouncycastle.openpgp.PGPLiteralDataGenerator; +import org.bouncycastle.openpgp.PGPObjectFactory; +import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData; import org.bouncycastle.openpgp.bc.BcPGPObjectFactory; import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; import org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder; @@ -26,9 +33,17 @@ import org.bouncycastle.util.Arrays; import org.bouncycastle.util.io.Streams; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.charset.StandardCharsets; -import java.security.*; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.Date; public class LegacyX25519KeyPairTest @@ -100,7 +115,8 @@ private void testV4MessageEncryptionDecryptionWithJcaKey() } private void testV4MessageEncryptionDecryptionWithBcKey() - throws PGPException, IOException { + throws PGPException, IOException + { Date date = currentTimeRounded(); X25519KeyPairGenerator gen = new X25519KeyPairGenerator(); gen.init(new X25519KeyGenerationParameters(new SecureRandom())); diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyX448KeyPairTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyX448KeyPairTest.java index 61c04c5f54..616d9bd026 100644 --- a/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyX448KeyPairTest.java +++ b/pg/src/test/java/org/bouncycastle/openpgp/test/LegacyX448KeyPairTest.java @@ -1,6 +1,8 @@ package org.bouncycastle.openpgp.test; -import org.bouncycastle.bcpg.*; +import org.bouncycastle.bcpg.ECDHPublicBCPGKey; +import org.bouncycastle.bcpg.ECSecretBCPGKey; +import org.bouncycastle.bcpg.PublicKeyAlgorithmTags; import org.bouncycastle.crypto.AsymmetricCipherKeyPair; import org.bouncycastle.crypto.generators.X448KeyPairGenerator; import org.bouncycastle.crypto.params.X448KeyGenerationParameters; @@ -11,7 +13,11 @@ import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair; import java.io.IOException; -import java.security.*; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.Date; public class LegacyX448KeyPairTest