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 2022/08/20 20:21:46 UTC
[commons-crypto] branch master updated: Remove trailing whitespace, use final, nest less, use compact arrays
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
The following commit(s) were added to refs/heads/master by this push:
new 8b11bcb Remove trailing whitespace, use final, nest less, use compact arrays
8b11bcb is described below
commit 8b11bcb5c1ba1d51e2dd87cc27d40cd3d972bc6b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 20 16:21:41 2022 -0400
Remove trailing whitespace, use final, nest less, use compact arrays
---
.../java/org/apache/commons/crypto/OsInfo.java | 15 ++++++----
.../commons/crypto/cipher/OpenSslCommonMode.java | 5 ++--
.../crypto/cipher/OpenSslGaloisCounterMode.java | 17 +++++------
.../commons/crypto/jna/OpenSsl10XNativeJna.java | 32 ++++++++++----------
.../commons/crypto/jna/OpenSsl11XNativeJna.java | 32 ++++++++++----------
.../commons/crypto/jna/OpenSsl20XNativeJna.java | 32 ++++++++++----------
.../commons/crypto/jna/OpenSslJnaCipher.java | 5 ++--
.../commons/crypto/jna/OpenSslNativeJna.java | 2 +-
.../commons/crypto/random/OpenSslCryptoRandom.java | 4 +--
.../commons/crypto/stream/CryptoInputStream.java | 13 +++++----
.../crypto/stream/CtrCryptoInputStream.java | 34 +++++++++++-----------
.../commons/crypto/stream/input/StreamInput.java | 3 +-
.../commons/crypto/utils/ReflectionUtils.java | 8 ++---
.../commons/crypto/cipher/AbstractCipherTest.java | 2 +-
.../commons/crypto/cipher/GcmCipherTest.java | 4 +--
.../commons/crypto/jna/OpenSslNativeJnaTest.java | 2 +-
.../crypto/random/JavaCryptoRandomTest.java | 4 +--
.../stream/PositionedCryptoInputStreamTest.java | 24 +++++++--------
18 files changed, 117 insertions(+), 121 deletions(-)
diff --git a/src/main/java/org/apache/commons/crypto/OsInfo.java b/src/main/java/org/apache/commons/crypto/OsInfo.java
index cd12938..d5b23cf 100644
--- a/src/main/java/org/apache/commons/crypto/OsInfo.java
+++ b/src/main/java/org/apache/commons/crypto/OsInfo.java
@@ -118,7 +118,8 @@ final class OsInfo {
if ("--os".equals(args[0])) {
System.out.print(getOSName());
return;
- } else if ("--arch".equals(args[0])) {
+ }
+ if ("--arch".equals(args[0])) {
System.out.print(getArchName());
return;
}
@@ -185,15 +186,17 @@ final class OsInfo {
private static String translateOSNameToFolderName(final String osName) {
if (osName.contains("Windows")) {
return "Windows";
- } else if (osName.contains("Mac")) {
+ }
+ if (osName.contains("Mac")) {
return "Mac";
- } else if (osName.contains("Linux")) {
+ }
+ if (osName.contains("Linux")) {
return "Linux";
- } else if (osName.contains("AIX")) {
+ }
+ if (osName.contains("AIX")) {
return "AIX";
- } else {
- return osName.replaceAll("\\W", "");
}
+ return osName.replaceAll("\\W", "");
}
/**
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSslCommonMode.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSslCommonMode.java
index 6ca17bb..4102b6e 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSslCommonMode.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSslCommonMode.java
@@ -42,12 +42,11 @@ class OpenSslCommonMode extends OpenSslFeedbackCipher {
throws InvalidAlgorithmParameterException {
this.cipherMode = mode;
final byte[] iv;
- if (params instanceof IvParameterSpec) {
- iv = ((IvParameterSpec) params).getIV();
- } else {
+ if (!(params instanceof IvParameterSpec)) {
// other AlgorithmParameterSpec is not supported now.
throw new InvalidAlgorithmParameterException("Illegal parameters");
}
+ iv = ((IvParameterSpec) params).getIV();
context = OpenSslNative.init(context, mode, algorithmMode, padding, key, iv);
}
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java
index 79950ed..9abe02e 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java
@@ -63,14 +63,13 @@ class OpenSslGaloisCounterMode extends OpenSslFeedbackCipher {
this.cipherMode = mode;
final byte[] iv;
- if (params instanceof GCMParameterSpec) {
- final GCMParameterSpec gcmParam = (GCMParameterSpec) params;
- iv = gcmParam.getIV();
- this.tagBitLen = gcmParam.getTLen();
- } else {
+ if (!(params instanceof GCMParameterSpec)) {
// other AlgorithmParameterSpec is not supported now.
throw new InvalidAlgorithmParameterException("Illegal parameters");
}
+ final GCMParameterSpec gcmParam = (GCMParameterSpec) params;
+ iv = gcmParam.getIV();
+ this.tagBitLen = gcmParam.getTLen();
if (this.cipherMode == OpenSsl.DECRYPT_MODE) {
inBuffer = new ByteArrayOutputStream();
@@ -212,7 +211,6 @@ class OpenSslGaloisCounterMode extends OpenSslFeedbackCipher {
// retrieve tag
tag.put(inputFinal, inputFinal.length - getTagLen(), getTagLen());
- tag.flip();
} else {
// if no buffered input, just use the input directly
@@ -228,8 +226,8 @@ class OpenSslGaloisCounterMode extends OpenSslFeedbackCipher {
// retrieve tag
tag.put(input);
- tag.flip();
}
+ tag.flip();
// set tag to EVP_Cipher for integrity verification in doFinal
evpCipherCtxCtrl(context, OpenSslEvpCtrlValues.AEAD_SET_TAG.getValue(),
@@ -270,13 +268,12 @@ class OpenSslGaloisCounterMode extends OpenSslFeedbackCipher {
@Override
public void updateAAD(final byte[] aad) {
// must be called after initialized.
- if (aadBuffer != null) {
- aadBuffer.write(aad, 0, aad.length);
- } else {
+ if (aadBuffer == null) {
// update has already been called
throw new IllegalStateException
("Update has been called; no more AAD data");
}
+ aadBuffer.write(aad, 0, aad.length);
}
private void processAAD() {
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java b/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java
index 2b5d7c0..2a2d6ba 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java
@@ -324,32 +324,32 @@ class OpenSsl10XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public PointerByReference _ENGINE_by_id(String string) {
+ public PointerByReference _ENGINE_by_id(final String string) {
return ENGINE_by_id(string);
}
@Override
- public int _ENGINE_finish(PointerByReference rdrandEngine) {
+ public int _ENGINE_finish(final PointerByReference rdrandEngine) {
return ENGINE_finish(rdrandEngine);
}
@Override
- public int _ENGINE_free(PointerByReference rdrandEngine) {
+ public int _ENGINE_free(final PointerByReference rdrandEngine) {
return ENGINE_free(rdrandEngine);
}
@Override
- public int _ENGINE_init(PointerByReference rdrandEngine) {
+ public int _ENGINE_init(final PointerByReference rdrandEngine) {
return ENGINE_init(rdrandEngine);
}
@Override
- public int _ENGINE_set_default(PointerByReference rdrandEngine, int flags) {
+ public int _ENGINE_set_default(final PointerByReference rdrandEngine, final int flags) {
return ENGINE_set_default(rdrandEngine, flags);
}
@Override
- public String _ERR_error_string(NativeLong err, char[] buff) {
+ public String _ERR_error_string(final NativeLong err, final char[] buff) {
return ERR_error_string(err, buff);
}
@@ -389,7 +389,7 @@ class OpenSsl10XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public void _EVP_CIPHER_CTX_free(PointerByReference context) {
+ public void _EVP_CIPHER_CTX_free(final PointerByReference context) {
EVP_CIPHER_CTX_free(context);
}
@@ -399,29 +399,29 @@ class OpenSsl10XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public int _EVP_CIPHER_CTX_set_padding(PointerByReference context, int padding) {
+ public int _EVP_CIPHER_CTX_set_padding(final PointerByReference context, final int padding) {
return EVP_CIPHER_CTX_set_padding(context, padding);
}
@Override
- public int _EVP_CipherFinal_ex(PointerByReference context, ByteBuffer outBuffer, int[] outlen) {
+ public int _EVP_CipherFinal_ex(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen) {
return EVP_CipherFinal_ex(context, outBuffer, outlen);
}
@Override
- public int _EVP_CipherInit_ex(PointerByReference context, PointerByReference algo, PointerByReference impl, byte[] encoded,
- byte[] iv, int cipherMode) {
+ public int _EVP_CipherInit_ex(final PointerByReference context, final PointerByReference algo, final PointerByReference impl, final byte[] encoded,
+ final byte[] iv, final int cipherMode) {
return EVP_CipherInit_ex(context, algo, impl, encoded, iv, cipherMode);
}
@Override
- public int _EVP_CipherUpdate(PointerByReference context, ByteBuffer outBuffer, int[] outlen, ByteBuffer inBuffer,
- int remaining) {
+ public int _EVP_CipherUpdate(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen, final ByteBuffer inBuffer,
+ final int remaining) {
return EVP_CipherUpdate(context, outBuffer, outlen, inBuffer, remaining);
}
@Override
- public int _RAND_bytes(ByteBuffer buf, int length) {
+ public int _RAND_bytes(final ByteBuffer buf, final int length) {
return RAND_bytes(buf, length) ;
}
@@ -436,7 +436,7 @@ class OpenSsl10XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public String _OpenSSL_version(int i) {
+ public String _OpenSSL_version(final int i) {
return SSLeay_version(i);
}
@@ -451,7 +451,7 @@ class OpenSsl10XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public void _EVP_CIPHER_CTX_cleanup(PointerByReference context) {
+ public void _EVP_CIPHER_CTX_cleanup(final PointerByReference context) {
EVP_CIPHER_CTX_cleanup(context);
}
}
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java b/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
index 92ddc68..adf023e 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
@@ -280,32 +280,32 @@ class OpenSsl11XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public PointerByReference _ENGINE_by_id(String string) {
+ public PointerByReference _ENGINE_by_id(final String string) {
return ENGINE_by_id(string);
}
@Override
- public int _ENGINE_finish(PointerByReference rdrandEngine) {
+ public int _ENGINE_finish(final PointerByReference rdrandEngine) {
return ENGINE_finish(rdrandEngine);
}
@Override
- public int _ENGINE_free(PointerByReference rdrandEngine) {
+ public int _ENGINE_free(final PointerByReference rdrandEngine) {
return ENGINE_free(rdrandEngine);
}
@Override
- public int _ENGINE_init(PointerByReference rdrandEngine) {
+ public int _ENGINE_init(final PointerByReference rdrandEngine) {
return ENGINE_init(rdrandEngine);
}
@Override
- public int _ENGINE_set_default(PointerByReference rdrandEngine, int flags) {
+ public int _ENGINE_set_default(final PointerByReference rdrandEngine, final int flags) {
return ENGINE_set_default(rdrandEngine, flags);
}
@Override
- public String _ERR_error_string(NativeLong err, char[] buff) {
+ public String _ERR_error_string(final NativeLong err, final char[] buff) {
return ERR_error_string(err, buff);
}
@@ -345,7 +345,7 @@ class OpenSsl11XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public void _EVP_CIPHER_CTX_free(PointerByReference context) {
+ public void _EVP_CIPHER_CTX_free(final PointerByReference context) {
EVP_CIPHER_CTX_free(context);
}
@@ -355,29 +355,29 @@ class OpenSsl11XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public int _EVP_CIPHER_CTX_set_padding(PointerByReference context, int padding) {
+ public int _EVP_CIPHER_CTX_set_padding(final PointerByReference context, final int padding) {
return EVP_CIPHER_CTX_set_padding(context, padding);
}
@Override
- public int _EVP_CipherFinal_ex(PointerByReference context, ByteBuffer outBuffer, int[] outlen) {
+ public int _EVP_CipherFinal_ex(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen) {
return EVP_CipherFinal_ex(context, outBuffer, outlen);
}
@Override
- public int _EVP_CipherInit_ex(PointerByReference context, PointerByReference algo, PointerByReference impl, byte[] encoded,
- byte[] iv, int cipherMode) {
+ public int _EVP_CipherInit_ex(final PointerByReference context, final PointerByReference algo, final PointerByReference impl, final byte[] encoded,
+ final byte[] iv, final int cipherMode) {
return EVP_CipherInit_ex(context, algo, impl, encoded, iv, cipherMode);
}
@Override
- public int _EVP_CipherUpdate(PointerByReference context, ByteBuffer outBuffer, int[] outlen, ByteBuffer inBuffer,
- int remaining) {
+ public int _EVP_CipherUpdate(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen, final ByteBuffer inBuffer,
+ final int remaining) {
return EVP_CipherUpdate(context, outBuffer, outlen, inBuffer, remaining);
}
@Override
- public int _RAND_bytes(ByteBuffer buf, int length) {
+ public int _RAND_bytes(final ByteBuffer buf, final int length) {
return RAND_bytes(buf, length) ;
}
@@ -392,7 +392,7 @@ class OpenSsl11XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public String _OpenSSL_version(int i) {
+ public String _OpenSSL_version(final int i) {
return OpenSSL_version(i);
}
@@ -407,7 +407,7 @@ class OpenSsl11XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public void _EVP_CIPHER_CTX_cleanup(PointerByReference context) {
+ public void _EVP_CIPHER_CTX_cleanup(final PointerByReference context) {
// Not available
}
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSsl20XNativeJna.java b/src/main/java/org/apache/commons/crypto/jna/OpenSsl20XNativeJna.java
index eca1ef9..ae1cb49 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSsl20XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSsl20XNativeJna.java
@@ -315,32 +315,32 @@ class OpenSsl20XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public PointerByReference _ENGINE_by_id(String string) {
+ public PointerByReference _ENGINE_by_id(final String string) {
return ENGINE_by_id(string);
}
@Override
- public int _ENGINE_finish(PointerByReference rdrandEngine) {
+ public int _ENGINE_finish(final PointerByReference rdrandEngine) {
return ENGINE_finish(rdrandEngine);
}
@Override
- public int _ENGINE_free(PointerByReference rdrandEngine) {
+ public int _ENGINE_free(final PointerByReference rdrandEngine) {
return ENGINE_free(rdrandEngine);
}
@Override
- public int _ENGINE_init(PointerByReference rdrandEngine) {
+ public int _ENGINE_init(final PointerByReference rdrandEngine) {
return ENGINE_init(rdrandEngine);
}
@Override
- public int _ENGINE_set_default(PointerByReference rdrandEngine, int flags) {
+ public int _ENGINE_set_default(final PointerByReference rdrandEngine, final int flags) {
return ENGINE_set_default(rdrandEngine, flags);
}
@Override
- public String _ERR_error_string(NativeLong err, char[] buff) {
+ public String _ERR_error_string(final NativeLong err, final char[] buff) {
return ERR_error_string(err, buff);
}
@@ -380,7 +380,7 @@ class OpenSsl20XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public void _EVP_CIPHER_CTX_free(PointerByReference context) {
+ public void _EVP_CIPHER_CTX_free(final PointerByReference context) {
EVP_CIPHER_CTX_free(context);
}
@@ -390,29 +390,29 @@ class OpenSsl20XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public int _EVP_CIPHER_CTX_set_padding(PointerByReference context, int padding) {
+ public int _EVP_CIPHER_CTX_set_padding(final PointerByReference context, final int padding) {
return EVP_CIPHER_CTX_set_padding(context, padding);
}
@Override
- public int _EVP_CipherFinal_ex(PointerByReference context, ByteBuffer outBuffer, int[] outlen) {
+ public int _EVP_CipherFinal_ex(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen) {
return EVP_CipherFinal_ex(context, outBuffer, outlen);
}
@Override
- public int _EVP_CipherInit_ex(PointerByReference context, PointerByReference algo, PointerByReference impl, byte[] encoded,
- byte[] iv, int cipherMode) {
+ public int _EVP_CipherInit_ex(final PointerByReference context, final PointerByReference algo, final PointerByReference impl, final byte[] encoded,
+ final byte[] iv, final int cipherMode) {
return EVP_CipherInit_ex(context, algo, impl, encoded, iv, cipherMode);
}
@Override
- public int _EVP_CipherUpdate(PointerByReference context, ByteBuffer outBuffer, int[] outlen, ByteBuffer inBuffer,
- int remaining) {
+ public int _EVP_CipherUpdate(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen, final ByteBuffer inBuffer,
+ final int remaining) {
return EVP_CipherUpdate(context, outBuffer, outlen, inBuffer, remaining);
}
@Override
- public int _RAND_bytes(ByteBuffer buf, int length) {
+ public int _RAND_bytes(final ByteBuffer buf, final int length) {
return RAND_bytes(buf, length) ;
}
@@ -427,7 +427,7 @@ class OpenSsl20XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public String _OpenSSL_version(int i) {
+ public String _OpenSSL_version(final int i) {
return SSLeay_version(i);
}
@@ -442,7 +442,7 @@ class OpenSsl20XNativeJna implements OpenSslInterfaceNativeJna {
}
@Override
- public void _EVP_CIPHER_CTX_cleanup(PointerByReference context) {
+ public void _EVP_CIPHER_CTX_cleanup(final PointerByReference context) {
EVP_CIPHER_CTX_cleanup(context);
}
}
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
index d1e8ab2..acf46ca 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
@@ -97,13 +97,12 @@ class OpenSslJnaCipher implements CryptoCipher {
cipherMode = OpenSslNativeJna.OOSL_JNA_ENCRYPT_MODE;
}
final byte[] iv;
- if (params instanceof IvParameterSpec) {
- iv = ((IvParameterSpec) params).getIV();
- } else {
+ if (!(params instanceof IvParameterSpec)) {
// other AlgorithmParameterSpec such as GCMParameterSpec is not
// supported now.
throw new InvalidAlgorithmParameterException("Illegal parameters");
}
+ iv = ((IvParameterSpec) params).getIV();
if ((algMode == AlgorithmMode.AES_CBC || algMode == AlgorithmMode.AES_CTR) && iv.length != IV_LENGTH) {
throw new InvalidAlgorithmParameterException("Wrong IV length: must be 16 bytes long");
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java b/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
index 794f57d..57929d8 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
@@ -44,7 +44,7 @@ class OpenSslNativeJna {
public static final long VERSION_2_0_X = 0x20000000;
private static final OpenSslInterfaceNativeJna JnaImplementation;
-
+
static {
final String libraryName = System.getProperty(Crypto.CONF_PREFIX + OpenSslNativeJna.class.getSimpleName(), "crypto");
OpenSslJna.debug("NativeLibrary.getInstance('%s')%n", libraryName);
diff --git a/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java b/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
index 33e2140..67a9b3b 100644
--- a/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
+++ b/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
@@ -65,7 +65,7 @@ class OpenSslCryptoRandom extends Random implements CryptoRandom {
// Check that nextRandBytes works (is this really needed?)
try {
checkNative();
- } catch (GeneralSecurityException e) {
+ } catch (final GeneralSecurityException e) {
throw new IllegalStateException(e);
}
if (!OpenSslCryptoRandomNative.nextRandBytes(new byte[1])) {
@@ -139,7 +139,7 @@ class OpenSslCryptoRandom extends Random implements CryptoRandom {
/**
* Generates a user-specified number of random bytes. It's thread-safe.
- * Overrides {@link Random}.
+ * Overrides {@link Random}.
*
* @param bytes the array to be filled in with random bytes.
*/
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 27afbf9..f22a22b 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
@@ -252,7 +252,8 @@ public class CryptoInputStream extends InputStream implements
Objects.requireNonNull(array, "array");
if (off < 0 || len < 0 || len > array.length - off) {
throw new IndexOutOfBoundsException();
- } else if (len == 0) {
+ }
+ if (len == 0) {
return 0;
}
@@ -508,13 +509,13 @@ public class CryptoInputStream extends InputStream implements
// End of the stream
return EOS;
- } else if (n == 0) {
+ }
+ if (n == 0) {
// No data is read, but the stream is not end yet
return 0;
- } else {
- decrypt();
- return outBuffer.remaining();
}
+ decrypt();
+ return outBuffer.remaining();
}
/**
@@ -590,7 +591,7 @@ public class CryptoInputStream extends InputStream implements
.clean(); */
final String SUN_CLASS = "sun.nio.ch.DirectBuffer";
final Class<?>[] interfaces = buffer.getClass().getInterfaces();
- final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
+ final Object[] EMPTY_OBJECT_ARRAY = {};
for (final Class<?> clazz : interfaces) {
if (clazz.getName().equals(SUN_CLASS)) {
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 47058f3..58712c4 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
@@ -265,27 +265,27 @@ public class CtrCryptoInputStream extends CryptoInputStream {
if (n == 0) {
return 0;
- } else if (n <= outBuffer.remaining()) {
+ }
+ if (n <= outBuffer.remaining()) {
final int pos = outBuffer.position() + (int) n;
outBuffer.position(pos);
return n;
- } else {
- /*
- * Subtract outBuffer.remaining() to see how many bytes we need to
- * skip in the underlying stream. Add outBuffer.remaining() to the
- * actual number of skipped bytes in the underlying stream to get
- * the number of skipped bytes from the user's point of view.
- */
- n -= outBuffer.remaining();
- long skipped = input.skip(n);
- if (skipped < 0) {
- skipped = 0;
- }
- final long pos = streamOffset + skipped;
- skipped += outBuffer.remaining();
- resetStreamOffset(pos);
- return skipped;
}
+ /*
+ * Subtract outBuffer.remaining() to see how many bytes we need to
+ * skip in the underlying stream. Add outBuffer.remaining() to the
+ * actual number of skipped bytes in the underlying stream to get
+ * the number of skipped bytes from the user's point of view.
+ */
+ n -= outBuffer.remaining();
+ long skipped = input.skip(n);
+ if (skipped < 0) {
+ skipped = 0;
+ }
+ final long pos = streamOffset + skipped;
+ skipped += outBuffer.remaining();
+ resetStreamOffset(pos);
+ return skipped;
}
/**
diff --git a/src/main/java/org/apache/commons/crypto/stream/input/StreamInput.java b/src/main/java/org/apache/commons/crypto/stream/input/StreamInput.java
index 76c1634..3727017 100644
--- a/src/main/java/org/apache/commons/crypto/stream/input/StreamInput.java
+++ b/src/main/java/org/apache/commons/crypto/stream/input/StreamInput.java
@@ -67,7 +67,8 @@ public class StreamInput implements Input {
read = EOS;
}
break;
- } else if (n > 0) {
+ }
+ if (n > 0) {
dst.put(buf, 0, n);
read += n;
remaining -= n;
diff --git a/src/main/java/org/apache/commons/crypto/utils/ReflectionUtils.java b/src/main/java/org/apache/commons/crypto/utils/ReflectionUtils.java
index dbde489..1650472 100644
--- a/src/main/java/org/apache/commons/crypto/utils/ReflectionUtils.java
+++ b/src/main/java/org/apache/commons/crypto/utils/ReflectionUtils.java
@@ -137,11 +137,11 @@ public final class ReflectionUtils {
// two putters can race here, but they'll put the same class
map.put(name, new WeakReference<>(clazz));
return clazz;
- } else if (clazz == NEGATIVE_CACHE_SENTINEL) {
+ }
+ if (clazz == NEGATIVE_CACHE_SENTINEL) {
return null; // not found
- } else {
- // cache hit
- return clazz;
}
+ // cache hit
+ return clazz;
}
}
diff --git a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
index 15b8398..01f807f 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
@@ -275,7 +275,7 @@ public abstract class AbstractCipherTest {
// check update method with inputs whose sizes are the multiple of
// block size or not
- final int[] bufferLenList = new int[] { 2 * 1024 - 128, 2 * 1024 - 125 };
+ final int[] bufferLenList = { 2 * 1024 - 128, 2 * 1024 - 125 };
for (final int bufferLen : bufferLenList) {
resetCipher(transformation, key, iv);
diff --git a/src/test/java/org/apache/commons/crypto/cipher/GcmCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/GcmCipherTest.java
index ceb60ff..f36ab44 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/GcmCipherTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/GcmCipherTest.java
@@ -252,7 +252,7 @@ public class GcmCipherTest {
final Random r = new Random();
final byte[] keyBytes = new byte[32];
- final byte[] input = new byte[0]; // no input for GMAC
+ final byte[] input = {}; // no input for GMAC
final byte[] ivBytes = new byte[16];
final byte[] tag_orig = new byte[16]; // JDK's tag
@@ -302,7 +302,7 @@ public class GcmCipherTest {
public void testGMacTamperedData() throws Exception {
final Random r = new Random();
final byte[] keyBytes = new byte[32];
- final byte[] input = new byte[0];
+ final byte[] input = {};
final byte[] ivBytes = new byte[16];
final byte[] tag = new byte[16];
diff --git a/src/test/java/org/apache/commons/crypto/jna/OpenSslNativeJnaTest.java b/src/test/java/org/apache/commons/crypto/jna/OpenSslNativeJnaTest.java
index fc89b0d..f6ae77e 100644
--- a/src/test/java/org/apache/commons/crypto/jna/OpenSslNativeJnaTest.java
+++ b/src/test/java/org/apache/commons/crypto/jna/OpenSslNativeJnaTest.java
@@ -26,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class OpenSslNativeJnaTest {
@Test
- public void test(TestReporter reporter) {
+ public void test(final TestReporter reporter) {
if (OpenSslJna.isEnabled()) {
reporter.publishEntry(String.format("JNA loaded OK for lib version 0x%x: ", OpenSslNativeJna.VERSION));
} else {
diff --git a/src/test/java/org/apache/commons/crypto/random/JavaCryptoRandomTest.java b/src/test/java/org/apache/commons/crypto/random/JavaCryptoRandomTest.java
index 12f29ae..881fbe3 100644
--- a/src/test/java/org/apache/commons/crypto/random/JavaCryptoRandomTest.java
+++ b/src/test/java/org/apache/commons/crypto/random/JavaCryptoRandomTest.java
@@ -18,7 +18,6 @@
package org.apache.commons.crypto.random;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -26,7 +25,6 @@ import java.security.GeneralSecurityException;
import java.util.Properties;
import java.util.Random;
-import org.apache.commons.crypto.utils.Utils;
import org.junit.jupiter.api.Test;
public class JavaCryptoRandomTest extends AbstractRandomTest {
@@ -47,7 +45,7 @@ public class JavaCryptoRandomTest extends AbstractRandomTest {
public void testNextIntIsntActuallyRandomNextInt() throws Exception {
final CryptoRandom cr = getCryptoRandom();
final Random r = (Random) cr;
- final long seed = 1654421930011l; // System.getCurrentMillis() on 2022-June-05, 11:39
+ final long seed = 1654421930011L; // System.getCurrentMillis() on 2022-June-05, 11:39
final Random otherRandom = new Random(seed);
final Random otherRandom2 = new Random();
otherRandom2.setSeed(seed);
diff --git a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
index 0926b9e..8bc0dec 100644
--- a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
@@ -148,12 +148,11 @@ public class PositionedCryptoInputStreamTest {
compareByteArray(testData, position, bytes2, pn2);
}
- if (n > 0) {
- compareByteArray(testData, position, buf.array(), n);
- position += n;
- } else {
+ if (n <= 0) {
break;
}
+ compareByteArray(testData, position, buf.array(), n);
+ position += n;
}
}
}
@@ -233,12 +232,11 @@ public class PositionedCryptoInputStreamTest {
in.seek(position);
final ByteBuffer buf = ByteBuffer.allocate(length);
final int n = in.read(buf);
- if (n > 0) {
- compareByteArray(testData, position, buf.array(), n);
- position += n;
- } else {
+ if (n <= 0) {
break;
}
+ compareByteArray(testData, position, buf.array(), n);
+ position += n;
}
}
}
@@ -258,12 +256,11 @@ public class PositionedCryptoInputStreamTest {
while (position < total) {
final byte[] bytes = new byte[length];
final int n = in.read(position, bytes, 0, length);
- if (n >= 0) {
- compareByteArray(testData, position, bytes, n);
- position += n;
- } else {
+ if (n < 0) {
break;
}
+ compareByteArray(testData, position, bytes, n);
+ position += n;
}
}
}
@@ -394,7 +391,8 @@ public class PositionedCryptoInputStreamTest {
public void seek(final long position) throws IOException {
if (pos < 0) {
throw new IOException("Negative seek offset");
- } else if (position >= 0 && position < count) {
+ }
+ if (position >= 0 && position < count) {
pos = position;
} else {
// to the end of file