From ac61273f6dd031e271d35c82a850e707a3451385 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 22 Jun 2024 17:27:10 -0400 Subject: [PATCH] Fix PMD UnnecessaryFullyQualifiedName --- .../java/org/apache/commons/crypto/Crypto.java | 10 +++++----- .../crypto/cipher/CryptoCipherFactory.java | 2 +- .../crypto/random/CryptoRandomFactory.java | 2 +- .../commons/crypto/stream/CryptoInputStream.java | 16 +++++++--------- .../crypto/stream/CtrCryptoInputStream.java | 8 ++++---- .../stream/PositionedCryptoInputStream.java | 5 ++--- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java index dbe33bc67..dc4729ab7 100644 --- a/src/main/java/org/apache/commons/crypto/Crypto.java +++ b/src/main/java/org/apache/commons/crypto/Crypto.java @@ -66,19 +66,19 @@ private static Properties getComponentProperties() { * The configuration key of the file name for loading crypto library. */ - public static final String LIB_NAME_KEY = Crypto.CONF_PREFIX + "lib.name"; + public static final String LIB_NAME_KEY = CONF_PREFIX + "lib.name"; // native lib related configuration keys /** * The configuration key of the path for loading crypto library. */ - public static final String LIB_PATH_KEY = Crypto.CONF_PREFIX + "lib.path"; + public static final String LIB_PATH_KEY = CONF_PREFIX + "lib.path"; /** * The configuration key of temp directory for extracting crypto library. * Defaults to "java.io.tempdir" if not found. */ - public static final String LIB_TEMPDIR_KEY = Crypto.CONF_PREFIX + "lib.tempdir"; + public static final String LIB_TEMPDIR_KEY = CONF_PREFIX + "lib.tempdir"; // property names related to SSL crypto library loading @@ -102,7 +102,7 @@ private static Properties getComponentProperties() { /** * Override property for the default SSL crypto library name when using JNA */ - public static final String JNA_LIBRARY_NAME_PROPERTY = Crypto.CONF_PREFIX + "OpenSslNativeJna"; + public static final String JNA_LIBRARY_NAME_PROPERTY = CONF_PREFIX + "OpenSslNativeJna"; /** Default name for loading SSL crypto library using JNA */ public static final String JNA_LIBRARY_NAME_DEFAULT = "crypto"; @@ -113,7 +113,7 @@ private static Properties getComponentProperties() { public static final String MACOS_LIBRARY_NAME_DEFAULT = "libcrypto.dylib"; /** If true, print some debug output */ - public static final boolean IS_DEBUG = Boolean.getBoolean(Crypto.CONF_PREFIX + "debug"); + public static final boolean IS_DEBUG = Boolean.getBoolean(CONF_PREFIX + "debug"); private static boolean quiet; diff --git a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java index 0935517f0..f2b446190 100644 --- a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java +++ b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java @@ -151,7 +151,7 @@ public Class getImplClass() { * If the property is missing or empty, {@link CLASSES_DEFAULT} is returned */ private static String getCipherClassString(final Properties props) { - String cipherClassString = props.getProperty(CryptoCipherFactory.CLASSES_KEY, CLASSES_DEFAULT); + String cipherClassString = props.getProperty(CLASSES_KEY, CLASSES_DEFAULT); if (cipherClassString.isEmpty()) { cipherClassString = CLASSES_DEFAULT; } diff --git a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java index 7ddecacbc..69ddabbf0 100644 --- a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java +++ b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java @@ -224,7 +224,7 @@ public static CryptoRandom getCryptoRandom(final Properties props) * @return the CryptoRandom class based on the props. */ private static String getRandomClassString(final Properties props) { - String randomClassString = props.getProperty(CryptoRandomFactory.CLASSES_KEY, CLASSES_DEFAULT); + String randomClassString = props.getProperty(CLASSES_KEY, CLASSES_DEFAULT); if (randomClassString.isEmpty()) { // TODO does it make sense to treat the empty string as the default? randomClassString = CLASSES_DEFAULT; } diff --git a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java index f2aa997b6..8f1bee5b6 100644 --- a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java +++ b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java @@ -78,8 +78,8 @@ public class CryptoInputStream extends InputStream implements ReadableByteChanne * @return the remaining buffer size. */ static int checkBufferSize(final CryptoCipher cipher, final int bufferSize) { - Utils.checkArgument(bufferSize >= CryptoInputStream.MIN_BUFFER_SIZE, - "Minimum value of buffer size is " + CryptoInputStream.MIN_BUFFER_SIZE + "."); + Utils.checkArgument(bufferSize >= MIN_BUFFER_SIZE, + "Minimum value of buffer size is " + MIN_BUFFER_SIZE + "."); return bufferSize - bufferSize % cipher.getBlockSize(); } @@ -103,8 +103,8 @@ static void checkStreamCipher(final CryptoCipher cipher) throws IOException { * @return the buffer size. * */ static int getBufferSize(final Properties props) { - final String bufferSizeStr = props.getProperty(CryptoInputStream.STREAM_BUFFER_SIZE_KEY, ""); - return bufferSizeStr.isEmpty() ? CryptoInputStream.STREAM_BUFFER_SIZE_DEFAULT : Integer.parseInt(bufferSizeStr); + final String bufferSizeStr = props.getProperty(STREAM_BUFFER_SIZE_KEY, ""); + return bufferSizeStr.isEmpty() ? STREAM_BUFFER_SIZE_DEFAULT : Integer.parseInt(bufferSizeStr); } private final byte[] oneByteBuf = new byte[1]; @@ -158,7 +158,7 @@ protected CryptoInputStream(final Input input, final CryptoCipher cipher, final final Key key, final AlgorithmParameterSpec params) throws IOException { this.input = input; this.cipher = cipher; - this.bufferSize = CryptoInputStream.checkBufferSize(cipher, bufferSize); + this.bufferSize = checkBufferSize(cipher, bufferSize); this.key = key; this.params = params; @@ -227,8 +227,7 @@ protected CryptoInputStream(final ReadableByteChannel channel, final CryptoCiphe public CryptoInputStream(final String transformation, final Properties properties, final InputStream inputStream, final Key key, final AlgorithmParameterSpec params) throws IOException { - this(inputStream, Utils.getCipherInstance(transformation, properties), - CryptoInputStream.getBufferSize(properties), key, params); + this(inputStream, Utils.getCipherInstance(transformation, properties), getBufferSize(properties), key, params); } /** @@ -249,8 +248,7 @@ public CryptoInputStream(final String transformation, public CryptoInputStream(final String transformation, final Properties properties, final ReadableByteChannel channel, final Key key, final AlgorithmParameterSpec params) throws IOException { - this(channel, Utils.getCipherInstance(transformation, properties), CryptoInputStream - .getBufferSize(properties), key, params); + this(channel, Utils.getCipherInstance(transformation, properties), getBufferSize(properties), key, params); } /** diff --git a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java index 6b4f4fd18..12da5122d 100644 --- a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java +++ b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java @@ -154,7 +154,7 @@ protected CtrCryptoInputStream(final Input input, final CryptoCipher cipher, this.initIV = iv.clone(); this.iv = iv.clone(); - CryptoInputStream.checkStreamCipher(cipher); + checkStreamCipher(cipher); resetStreamOffset(streamOffset); } @@ -224,7 +224,7 @@ public CtrCryptoInputStream(final Properties properties, final InputStream input final byte[] iv, final long streamOffset) throws IOException { this(inputStream, Utils.getCipherInstance( AES.CTR_NO_PADDING, properties), - CryptoInputStream.getBufferSize(properties), key, iv, streamOffset); + getBufferSize(properties), key, iv, streamOffset); } /** @@ -258,7 +258,7 @@ public CtrCryptoInputStream(final Properties properties, final ReadableByteChann final byte[] key, final byte[] iv, final long streamOffset) throws IOException { this(in, Utils.getCipherInstance( AES.CTR_NO_PADDING, properties), - CryptoInputStream.getBufferSize(properties), key, iv, streamOffset); + getBufferSize(properties), key, iv, streamOffset); } /** @@ -561,7 +561,7 @@ public int read(final ByteBuffer buf) throws IOException { */ protected void resetCipher(final long position) throws IOException { final long counter = getCounter(position); - CtrCryptoInputStream.calculateIV(initIV, counter, iv); + calculateIV(initIV, counter, iv); try { cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); } catch (final GeneralSecurityException e) { diff --git a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java index d7ad3a08e..3ced8349e 100644 --- a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java +++ b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java @@ -112,8 +112,7 @@ public void reset(final boolean reset) { @SuppressWarnings("resource") // The CryptoCipher returned by getCipherInstance() is closed by PositionedCryptoInputStream. public PositionedCryptoInputStream(final Properties properties, final Input in, final byte[] key, final byte[] iv, final long streamOffset) throws IOException { - this(properties, in, Utils.getCipherInstance(AES.CTR_NO_PADDING, properties), - CryptoInputStream.getBufferSize(properties), key, iv, streamOffset); + this(properties, in, Utils.getCipherInstance(AES.CTR_NO_PADDING, properties), getBufferSize(properties), key, iv, streamOffset); } /** @@ -391,7 +390,7 @@ public void readFully(final long position, final byte[] buffer, final int offset @SuppressWarnings("resource") // getCryptoCipher does not allocate private void resetCipher(final CipherState state, final long position, final byte[] iv) { final long counter = getCounter(position); - CtrCryptoInputStream.calculateIV(getInitIV(), counter, iv); + calculateIV(getInitIV(), counter, iv); try { state.getCryptoCipher().init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); } catch (final GeneralSecurityException e) {