Skip to content

Commit

Permalink
Fix PMD UnnecessaryFullyQualifiedName
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jun 22, 2024
1 parent c0d93b1 commit ac61273
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/main/java/org/apache/commons/crypto/Crypto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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";
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Class<? extends CryptoCipher> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ac61273

Please sign in to comment.