You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/06/22 21:28:45 UTC

(commons-crypto) 01/02: Fix PMD UnnecessaryFullyQualifiedName

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-crypto.git

commit ac61273f6dd031e271d35c82a850e707a3451385
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 22 17:27:10 2024 -0400

    Fix PMD UnnecessaryFullyQualifiedName
---
 src/main/java/org/apache/commons/crypto/Crypto.java      | 10 +++++-----
 .../commons/crypto/cipher/CryptoCipherFactory.java       |  2 +-
 .../commons/crypto/random/CryptoRandomFactory.java       |  2 +-
 .../apache/commons/crypto/stream/CryptoInputStream.java  | 16 +++++++---------
 .../commons/crypto/stream/CtrCryptoInputStream.java      |  8 ++++----
 .../crypto/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 dbe33bc6..dc4729ab 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 @@ public final class Crypto {
      * 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 @@ public final class Crypto {
     /**
      * 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 @@ public final class Crypto {
     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 0935517f..f2b44619 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 CryptoCipherFactory {
      * 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 7ddecacb..69ddabbf 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 class CryptoRandomFactory {
      * @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 f2aa997b..8f1bee5b 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 @@ public class CryptoInputStream extends InputStream implements ReadableByteChanne
      * @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 @@ public class CryptoInputStream extends InputStream implements ReadableByteChanne
             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 @@ public class CryptoInputStream extends InputStream implements ReadableByteChanne
     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 class CryptoInputStream extends InputStream implements ReadableByteChanne
     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 6b4f4fd1..12da5122 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 @@ public class CtrCryptoInputStream extends CryptoInputStream {
         this.initIV = iv.clone();
         this.iv = iv.clone();
 
-        CryptoInputStream.checkStreamCipher(cipher);
+        checkStreamCipher(cipher);
 
         resetStreamOffset(streamOffset);
     }
@@ -224,7 +224,7 @@ public class CtrCryptoInputStream extends CryptoInputStream {
             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 class CtrCryptoInputStream extends CryptoInputStream {
             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 class CtrCryptoInputStream extends CryptoInputStream {
      */
     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 d7ad3a08..3ced8349 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 class PositionedCryptoInputStream extends CtrCryptoInputStream {
     @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 class PositionedCryptoInputStream extends CtrCryptoInputStream {
     @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) {