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/12/11 17:13:02 UTC
[commons-crypto] branch master updated: Add @SuppressWarnings
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 637d89b Add @SuppressWarnings
637d89b is described below
commit 637d89bb1779c1024b7de2660ab32afab9726c86
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 11 12:12:58 2022 -0500
Add @SuppressWarnings
---
.../apache/commons/crypto/cipher/CryptoCipherFactory.java | 10 +++-------
.../org/apache/commons/crypto/stream/CryptoInputStream.java | 6 ++++--
.../org/apache/commons/crypto/stream/CryptoOutputStream.java | 2 ++
.../apache/commons/crypto/stream/CtrCryptoInputStream.java | 2 ++
.../apache/commons/crypto/stream/CtrCryptoOutputStream.java | 10 +++++-----
.../commons/crypto/stream/PositionedCryptoInputStream.java | 12 +++++++-----
6 files changed, 23 insertions(+), 19 deletions(-)
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 8824b32..e86c969 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
@@ -144,9 +144,7 @@ public class CryptoCipherFactory {
* @throws GeneralSecurityException if cipher initialize failed
* @throws IllegalArgumentException if no classname(s) were provided
*/
- public static CryptoCipher getCryptoCipher(final String transformation, final Properties properties)
- throws GeneralSecurityException {
-
+ public static CryptoCipher getCryptoCipher(final String transformation, final Properties properties) throws GeneralSecurityException {
final List<String> names = Utils.splitClassNames(getCipherClassString(properties), ",");
if (names.isEmpty()) {
throw new IllegalArgumentException("No classname(s) provided");
@@ -158,8 +156,7 @@ public class CryptoCipherFactory {
for (final String klass : names) {
try {
final Class<?> cls = ReflectionUtils.getClassByName(klass);
- cipher = ReflectionUtils.newInstance(cls.asSubclass
- (CryptoCipher.class), properties, transformation);
+ cipher = ReflectionUtils.newInstance(cls.asSubclass(CryptoCipher.class), properties, transformation);
break;
} catch (final Exception e) {
lastException = e;
@@ -170,8 +167,7 @@ public class CryptoCipherFactory {
if (cipher != null) {
return cipher;
}
- errorMessage.append(" is not available or transformation " +
- transformation + " is not supported.");
+ errorMessage.append(" is not available or transformation " + transformation + " is not supported.");
throw new GeneralSecurityException(errorMessage.toString(), lastException);
}
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 bc5a16e..5c4b46e 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
@@ -49,8 +49,8 @@ import org.apache.commons.crypto.utils.Utils;
*
*/
-public class CryptoInputStream extends InputStream implements
- ReadableByteChannel {
+public class CryptoInputStream extends InputStream implements ReadableByteChannel {
+
private final byte[] oneByteBuf = new byte[1];
/**
@@ -163,6 +163,7 @@ public class CryptoInputStream extends InputStream implements
* @param params the algorithm parameters.
* @throws IOException if an I/O error occurs.
*/
+ @SuppressWarnings("resource") // Closing the instance closes the StreamInput
protected CryptoInputStream(final InputStream inputStream, final CryptoCipher cipher,
final int bufferSize, final Key key, final AlgorithmParameterSpec params)
throws IOException {
@@ -179,6 +180,7 @@ public class CryptoInputStream extends InputStream implements
* @param params the algorithm parameters.
* @throws IOException if an I/O error occurs.
*/
+ @SuppressWarnings("resource") // Closing the instance closes the ChannelInput
protected CryptoInputStream(final ReadableByteChannel channel, final CryptoCipher cipher,
final int bufferSize, final Key key, final AlgorithmParameterSpec params)
throws IOException {
diff --git a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
index 443b2b3..c2e49de 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
@@ -138,6 +138,7 @@ public class CryptoOutputStream extends OutputStream implements
* @param params the algorithm parameters.
* @throws IOException if an I/O error occurs.
*/
+ @SuppressWarnings("resource") // Closing the instance closes the StreamOutput
protected CryptoOutputStream(final OutputStream outputStream, final CryptoCipher cipher,
final int bufferSize, final Key key, final AlgorithmParameterSpec params)
throws IOException {
@@ -154,6 +155,7 @@ public class CryptoOutputStream extends OutputStream implements
* @param params the algorithm parameters.
* @throws IOException if an I/O error occurs.
*/
+ @SuppressWarnings("resource") // Closing the instance closes the ChannelOutput
protected CryptoOutputStream(final WritableByteChannel channel, final CryptoCipher cipher,
final int bufferSize, final Key key, final AlgorithmParameterSpec params)
throws IOException {
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 5faed86..2dcfec9 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
@@ -201,6 +201,7 @@ public class CtrCryptoInputStream extends CryptoInputStream {
* @param streamOffset the start offset in the stream.
* @throws IOException if an I/O error occurs.
*/
+ @SuppressWarnings("resource") // Closing the instance closes the StreamInput
protected CtrCryptoInputStream(final InputStream inputStream, final CryptoCipher cipher,
final int bufferSize, final byte[] key, final byte[] iv, final long streamOffset)
throws IOException {
@@ -219,6 +220,7 @@ public class CtrCryptoInputStream extends CryptoInputStream {
* @param streamOffset the start offset in the stream.
* @throws IOException if an I/O error occurs.
*/
+ @SuppressWarnings("resource") // Closing the instance closes the ChannelInput
protected CtrCryptoInputStream(final ReadableByteChannel channel, final CryptoCipher cipher,
final int bufferSize, final byte[] key, final byte[] iv, final long streamOffset)
throws IOException {
diff --git a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java
index e3a0fbd..8a16e5d 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java
@@ -206,11 +206,11 @@ public class CtrCryptoOutputStream extends CryptoOutputStream {
* @param streamOffset the start offset in the data.
* @throws IOException if an I/O error occurs.
*/
+ @SuppressWarnings("resource") // Closing the instance closes the StreamOutput
protected CtrCryptoOutputStream(final OutputStream outputStream, final CryptoCipher cipher,
final int bufferSize, final byte[] key, final byte[] iv, final long streamOffset)
throws IOException {
- this(new StreamOutput(outputStream, bufferSize), cipher, bufferSize, key, iv,
- streamOffset);
+ this(new StreamOutput(outputStream, bufferSize), cipher, bufferSize, key, iv, streamOffset);
}
/**
@@ -224,11 +224,11 @@ public class CtrCryptoOutputStream extends CryptoOutputStream {
* @param streamOffset the start offset in the data.
* @throws IOException if an I/O error occurs.
*/
- protected CtrCryptoOutputStream(final WritableByteChannel channel,
+ @SuppressWarnings("resource") // Closing the instance closes the ChannelOutput
+ protected CtrCryptoOutputStream(final WritableByteChannel channel,
final CryptoCipher cipher, final int bufferSize, final byte[] key, final byte[] iv,
final long streamOffset) throws IOException {
- this(new ChannelOutput(channel), cipher, bufferSize, key, iv,
- streamOffset);
+ this(new ChannelOutput(channel), cipher, bufferSize, key, iv, streamOffset);
}
/**
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 a40f9bd..a0e7b04 100644
--- a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
@@ -232,6 +232,7 @@ public class PositionedCryptoInputStream extends CtrCryptoInputStream {
* @param outByteBuffer the output buffer.
* @throws IOException if an I/O error occurs.
*/
+ @SuppressWarnings("resource") // getCryptoCipher does not allocate
private void decryptBuffer(final CipherState state, final ByteBuffer inByteBuffer,
final ByteBuffer outByteBuffer) throws IOException {
final int inputSize = inByteBuffer.remaining();
@@ -285,6 +286,7 @@ public class PositionedCryptoInputStream extends CtrCryptoInputStream {
* @param position the offset from the start of the stream.
* @param iv the iv.
*/
+ @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);
@@ -370,7 +372,7 @@ public class PositionedCryptoInputStream extends CtrCryptoInputStream {
super.close();
}
- /** Clean direct buffer pool */
+ /** Cleans direct buffer pool */
private void cleanBufferPool() {
ByteBuffer buf;
while ((buf = bufferPool.poll()) != null) {
@@ -384,12 +386,12 @@ public class PositionedCryptoInputStream extends CtrCryptoInputStream {
private boolean reset;
/**
- * The constructor of {@link CipherState}.
+ * Constructs a new instance.
*
- * @param cipher the CryptoCipher instance.
+ * @param cryptoCipher the CryptoCipher instance.
*/
- public CipherState(final CryptoCipher cipher) {
- this.cryptoCipher = cipher;
+ public CipherState(final CryptoCipher cryptoCipher) {
+ this.cryptoCipher = cryptoCipher;
this.reset = false;
}