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 2023/10/22 13:15:32 UTC
[commons-crypto] branch master updated (50076e7 -> 5aa398e)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-crypto.git
from 50076e7 Test does not close resource
new d3530f5 Test does not close resources
new f3a5a6e Test does not close resources
new e3b29fd Test does not close resources
new c32f6eb Sort members
new 397709a ChannelInput.ChannelInput(ReadableByteChannel) now throws NullPointerException on null input
new 73b9c5b StreamInput.StreamInput(InputStream, int) now throws NullPointerException on null input
new 607d0da ChannelOutput.ChannelOutput(WritableByteChannel) now throws NullPointerException on null input
new 5aa398e StreamOutput.StreamOutput(OutputStream, int) now throws NullPointerException on null input
The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/changes/changes.xml | 4 +
.../commons/crypto/stream/input/ChannelInput.java | 4 +-
.../commons/crypto/stream/input/StreamInput.java | 4 +-
.../crypto/stream/output/ChannelOutput.java | 4 +-
.../commons/crypto/stream/output/StreamOutput.java | 6 +-
.../crypto/random/CryptoRandomFactoryTest.java | 22 ++--
.../random/ExceptionInInitializerErrorRandom.java | 4 +-
.../crypto/stream/AbstractCipherStreamTest.java | 112 +++++++++------------
8 files changed, 79 insertions(+), 81 deletions(-)
[commons-crypto] 07/08: ChannelOutput.ChannelOutput(WritableByteChannel) now throws NullPointerException on null input
Posted by gg...@apache.org.
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 607d0dab098e25c7bba8f17c81967919d0b6a7d8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 22 09:10:43 2023 -0400
ChannelOutput.ChannelOutput(WritableByteChannel) now throws
NullPointerException on null input
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/crypto/stream/output/ChannelOutput.java | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 986e7e9..46f422e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -74,6 +74,7 @@
<action dev="ggregory" type="fix" issue="CRYPTO-169" due-to="L. C. Hsieh, Yang Jie, Gary Gregory">Add protection for the ExceptionInInitializerError scenario to the CryptoRandomFactory#getCryptoRandom(Properties) method #258.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">ChannelInput.ChannelInput(ReadableByteChannel) now throws NullPointerException on null input.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">StreamInput.StreamInput(InputStream, int) now throws NullPointerException on null input.</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">ChannelOutput.ChannelOutput(WritableByteChannel) now throws NullPointerException on null input.</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump commons-parent from 56 to 64 #225.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump com.sun.xml.bind:jaxb-impl from 2.3.7 to 2.3.8.</action>
diff --git a/src/main/java/org/apache/commons/crypto/stream/output/ChannelOutput.java b/src/main/java/org/apache/commons/crypto/stream/output/ChannelOutput.java
index d1d5678..9fc617d 100644
--- a/src/main/java/org/apache/commons/crypto/stream/output/ChannelOutput.java
+++ b/src/main/java/org/apache/commons/crypto/stream/output/ChannelOutput.java
@@ -20,6 +20,7 @@ package org.apache.commons.crypto.stream.output;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
+import java.util.Objects;
import org.apache.commons.crypto.stream.CryptoOutputStream;
@@ -37,9 +38,10 @@ public class ChannelOutput implements Output {
* {@link org.apache.commons.crypto.stream.output.ChannelOutput}.
*
* @param channel the WritableByteChannel object.
+ * @throws NullPointerException if channel is null.
*/
public ChannelOutput(final WritableByteChannel channel) {
- this.channel = channel;
+ this.channel = Objects.requireNonNull(channel, "channel");
}
/**
[commons-crypto] 03/08: Test does not close resources
Posted by gg...@apache.org.
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 e3b29fde9a8f7d003dbce32de907efe802fe9ef9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 22 09:04:25 2023 -0400
Test does not close resources
---
.../crypto/stream/AbstractCipherStreamTest.java | 35 ++++++++++------------
1 file changed, 16 insertions(+), 19 deletions(-)
diff --git a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
index 4df58f4..a5bc510 100644
--- a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
@@ -308,26 +308,24 @@ public abstract class AbstractCipherStreamTest {
assumeJniPresence(cipherClass);
// Test InvalidAlgorithmParameters
- Exception ex = assertThrows(IOException.class, () -> newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData),
- AES.newSecretKeySpec(key), new GCMParameterSpec(0, new byte[0]), withChannel));
- assertEquals(ex.getMessage(),"Illegal parameters");
+ Exception ex = assertThrows(IOException.class, () -> newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData),
+ AES.newSecretKeySpec(key), new GCMParameterSpec(0, new byte[0]), withChannel));
+ assertEquals(ex.getMessage(), "Illegal parameters");
// Test InvalidAlgorithmParameters
- ex = assertThrows(IOException.class, () -> newCryptoOutputStream(transformation, props, baos,
- AES.newSecretKeySpec(key), new GCMParameterSpec(0,
- new byte[0]), withChannel));
- assertEquals(ex.getMessage(),"Illegal parameters");
+ ex = assertThrows(IOException.class,
+ () -> newCryptoOutputStream(transformation, props, baos, AES.newSecretKeySpec(key), new GCMParameterSpec(0, new byte[0]), withChannel));
+ assertEquals(ex.getMessage(), "Illegal parameters");
// Test Invalid Key
- assertThrows(IOException.class, () -> newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData),
- AES.newSecretKeySpec(new byte[10]), new IvParameterSpec(iv), withChannel));
- // Test Invalid Key
- assertThrows(IOException.class, () -> newCryptoOutputStream(transformation, props, baos, new byte[10],
+ assertThrows(IOException.class, () -> newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), AES.newSecretKeySpec(new byte[10]),
new IvParameterSpec(iv), withChannel));
+ // Test Invalid Key
+ assertThrows(IOException.class, () -> newCryptoOutputStream(transformation, props, baos, new byte[10], new IvParameterSpec(iv), withChannel));
// Test reading a closed stream.
InputStream closedIn;
- try (final InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData),
- getCipher(cipherClass), defaultBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = getCipher(cipherClass);
+ final InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, defaultBufferSize, iv, withChannel)) {
closedIn = in;
}
// Throw exception.
@@ -342,8 +340,7 @@ public abstract class AbstractCipherStreamTest {
}
// Test checking a closed stream.
- final OutputStream out = newCryptoOutputStream(transformation, props, baos, key, new IvParameterSpec(iv),
- withChannel);
+ final OutputStream out = newCryptoOutputStream(transformation, props, baos, key, new IvParameterSpec(iv), withChannel);
out.close();
// Throw exception.
assertThrows(IOException.class, ((CryptoOutputStream) out)::checkStream);
@@ -356,8 +353,8 @@ public abstract class AbstractCipherStreamTest {
}
// Test checkStreamCipher
- try {
- CryptoInputStream.checkStreamCipher(getCipher(cipherClass));
+ try (CryptoCipher cipher = getCipher(cipherClass)) {
+ CryptoInputStream.checkStreamCipher(cipher);
} catch (final IOException ioEx) {
assertEquals(ioEx.getMessage(), "AES/CTR/NoPadding is required");
} finally {
@@ -365,8 +362,8 @@ public abstract class AbstractCipherStreamTest {
}
// Test unsupported operation handling.
- try (final InputStream inNewCrytptoStr = newCryptoInputStream(new ByteArrayInputStream(encData),
- getCipher(cipherClass), defaultBufferSize, iv, false)) {
+ try (final InputStream inNewCrytptoStr = newCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass), defaultBufferSize, iv,
+ false)) {
closedIn.mark(0);
assertFalse(closedIn.markSupported());
ex = assertThrows(IOException.class, inNewCrytptoStr::reset);
[commons-crypto] 08/08: StreamOutput.StreamOutput(OutputStream, int) now throws NullPointerException on null input
Posted by gg...@apache.org.
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 5aa398e5c3cc693f7fc9b3659f29794c6632aa15
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 22 09:15:16 2023 -0400
StreamOutput.StreamOutput(OutputStream, int) now throws
NullPointerException on null input
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/crypto/stream/output/StreamOutput.java | 6 ++++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 46f422e..1e2f167 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -75,6 +75,7 @@
<action dev="ggregory" type="fix" due-to="Gary Gregory">ChannelInput.ChannelInput(ReadableByteChannel) now throws NullPointerException on null input.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">StreamInput.StreamInput(InputStream, int) now throws NullPointerException on null input.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">ChannelOutput.ChannelOutput(WritableByteChannel) now throws NullPointerException on null input.</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">StreamOutput.StreamOutput(OutputStream, int) now throws NullPointerException on null input.</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump commons-parent from 56 to 64 #225.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump com.sun.xml.bind:jaxb-impl from 2.3.7 to 2.3.8.</action>
diff --git a/src/main/java/org/apache/commons/crypto/stream/output/StreamOutput.java b/src/main/java/org/apache/commons/crypto/stream/output/StreamOutput.java
index 629be84..22fdce8 100644
--- a/src/main/java/org/apache/commons/crypto/stream/output/StreamOutput.java
+++ b/src/main/java/org/apache/commons/crypto/stream/output/StreamOutput.java
@@ -20,6 +20,7 @@ package org.apache.commons.crypto.stream.output;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
+import java.util.Objects;
import org.apache.commons.crypto.stream.CryptoOutputStream;
@@ -38,11 +39,12 @@ public class StreamOutput implements Output {
*
* @param out the OutputStream object.
* @param bufferSize the buffer size.
+ * @throws NullPointerException if channel is null.
*/
public StreamOutput(final OutputStream out, final int bufferSize) {
- this.out = out;
+ this.out = Objects.requireNonNull(out, "out");
this.bufferSize = bufferSize;
- buf = new byte[bufferSize];
+ this.buf = new byte[bufferSize];
}
/**
[commons-crypto] 02/08: Test does not close resources
Posted by gg...@apache.org.
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 f3a5a6eb7e836ba1dc59487e3cccf38809b867f0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 22 09:00:51 2023 -0400
Test does not close resources
---
.../org/apache/commons/crypto/stream/AbstractCipherStreamTest.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
index 918de98..4df58f4 100644
--- a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
@@ -274,9 +274,8 @@ public abstract class AbstractCipherStreamTest {
assertThrows(IndexOutOfBoundsException.class, () -> out.write(data, 0, data.length + 1));
out.flush();
- try (InputStream in = newCryptoInputStream(
- new ByteArrayInputStream(encData), out.getCipher(),
- defaultBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = out.getCipher();
+ InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, defaultBufferSize, iv, withChannel)) {
buf = ByteBuffer.allocate(dataLen + 100);
byteBufferReadCheck(in, buf, 0);
}
[commons-crypto] 06/08: StreamInput.StreamInput(InputStream, int) now throws NullPointerException on null input
Posted by gg...@apache.org.
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 73b9c5b8b2138ef1eee013e31c9951a2ed093fe8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 22 09:08:57 2023 -0400
StreamInput.StreamInput(InputStream, int) now throws
NullPointerException on null input
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/crypto/stream/input/StreamInput.java | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2ea292c..986e7e9 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -73,6 +73,7 @@
<action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate AES.AES().</action>
<action dev="ggregory" type="fix" issue="CRYPTO-169" due-to="L. C. Hsieh, Yang Jie, Gary Gregory">Add protection for the ExceptionInInitializerError scenario to the CryptoRandomFactory#getCryptoRandom(Properties) method #258.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">ChannelInput.ChannelInput(ReadableByteChannel) now throws NullPointerException on null input.</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">StreamInput.StreamInput(InputStream, int) now throws NullPointerException on null input.</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump commons-parent from 56 to 64 #225.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump com.sun.xml.bind:jaxb-impl from 2.3.7 to 2.3.8.</action>
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 6b6f244..674df6d 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
@@ -22,6 +22,7 @@ import static org.apache.commons.crypto.stream.CryptoInputStream.EOS;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
+import java.util.Objects;
import org.apache.commons.crypto.stream.CryptoInputStream;
@@ -40,9 +41,10 @@ public class StreamInput implements Input {
*
* @param inputStream the InputStream object.
* @param bufferSize the buffer size.
+ * @throws NullPointerException if inputStream is null.
*/
public StreamInput(final InputStream inputStream, final int bufferSize) {
- this.in = inputStream;
+ this.in = Objects.requireNonNull(inputStream, "inputStream");
this.bufferSize = bufferSize;
this.buf = new byte[bufferSize];
}
[commons-crypto] 05/08: ChannelInput.ChannelInput(ReadableByteChannel) now throws NullPointerException on null input
Posted by gg...@apache.org.
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 397709ad2e73ea03cac8d08b14a548ca53f286a4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 22 09:06:54 2023 -0400
ChannelInput.ChannelInput(ReadableByteChannel) now throws
NullPointerException on null input
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/crypto/stream/input/ChannelInput.java | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1938133..2ea292c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -72,6 +72,7 @@
<action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate Crypto.Crypto().</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate AES.AES().</action>
<action dev="ggregory" type="fix" issue="CRYPTO-169" due-to="L. C. Hsieh, Yang Jie, Gary Gregory">Add protection for the ExceptionInInitializerError scenario to the CryptoRandomFactory#getCryptoRandom(Properties) method #258.</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">ChannelInput.ChannelInput(ReadableByteChannel) now throws NullPointerException on null input.</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump commons-parent from 56 to 64 #225.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump com.sun.xml.bind:jaxb-impl from 2.3.7 to 2.3.8.</action>
diff --git a/src/main/java/org/apache/commons/crypto/stream/input/ChannelInput.java b/src/main/java/org/apache/commons/crypto/stream/input/ChannelInput.java
index 07dfdc1..23699c4 100644
--- a/src/main/java/org/apache/commons/crypto/stream/input/ChannelInput.java
+++ b/src/main/java/org/apache/commons/crypto/stream/input/ChannelInput.java
@@ -20,6 +20,7 @@ package org.apache.commons.crypto.stream.input;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
+import java.util.Objects;
import org.apache.commons.crypto.stream.CryptoInputStream;
@@ -39,9 +40,10 @@ public class ChannelInput implements Input {
* {@link org.apache.commons.crypto.stream.input.ChannelInput}.
*
* @param channel the ReadableByteChannel object.
+ * @throws NullPointerException if channel is null.
*/
public ChannelInput(final ReadableByteChannel channel) {
- this.channel = channel;
+ this.channel = Objects.requireNonNull(channel, "channel");
}
/**
[commons-crypto] 01/08: Test does not close resources
Posted by gg...@apache.org.
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 d3530f5e5a94d4312873081fb6f735dfbd37fa22
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 22 08:53:48 2023 -0400
Test does not close resources
---
.../crypto/stream/AbstractCipherStreamTest.java | 72 ++++++++++------------
1 file changed, 31 insertions(+), 41 deletions(-)
diff --git a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
index fa2d671..918de98 100644
--- a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
@@ -117,145 +117,135 @@ public abstract class AbstractCipherStreamTest {
}
protected void doByteBufferRead(final String cipherClass, final boolean withChannel)
- throws Exception {
+ throws Exception {
// Skip this test if no JNI
assumeJniPresence(cipherClass);
ByteBuffer buf = ByteBuffer.allocate(dataLen + 100);
// Default buffer size, initial buffer position is 0
- try (InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass),
- defaultBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = getCipher(cipherClass);
+ InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, defaultBufferSize, iv, withChannel)) {
byteBufferReadCheck(in, buf, 0);
}
// Default buffer size, initial buffer position is not 0
- try (InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass),
- defaultBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = getCipher(cipherClass);
+ InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, defaultBufferSize, iv, withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 11);
}
// Small buffer size, initial buffer position is 0
- try (InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass),
- smallBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = getCipher(cipherClass);
+ InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, smallBufferSize, iv, withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 0);
}
// Small buffer size, initial buffer position is not 0
- try (InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass),
- smallBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = getCipher(cipherClass);
+ InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, smallBufferSize, iv, withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 11);
}
// Direct buffer, default buffer size, initial buffer position is 0
- try (InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass),
- defaultBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = getCipher(cipherClass);
+ InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, defaultBufferSize, iv, withChannel)) {
buf = ByteBuffer.allocateDirect(dataLen + 100);
byteBufferReadCheck(in, buf, 0);
}
// Direct buffer, default buffer size, initial buffer position is not 0
- try (InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass),
- defaultBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = getCipher(cipherClass);
+ InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, defaultBufferSize, iv, withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 11);
}
// Direct buffer, small buffer size, initial buffer position is 0
- try (InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass),
- smallBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = getCipher(cipherClass);
+ InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, smallBufferSize, iv, withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 0);
}
// Direct buffer, small buffer size, initial buffer position is not 0
- try (InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass),
- smallBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = getCipher(cipherClass);
+ InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, smallBufferSize, iv, withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 11);
}
// Direct buffer, small buffer size, initial buffer position is 0, final read
- try (InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass),
- smallBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = getCipher(cipherClass);
+ InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, smallBufferSize, iv, withChannel)) {
buf.clear();
byteBufferFinalReadCheck(in, buf, 0);
}
// Default buffer size, initial buffer position is 0, insufficient dest buffer length
- try (InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass),
- defaultBufferSize, iv, withChannel)) {
+ try (CryptoCipher cipher = getCipher(cipherClass);
+ InputStream in = newCryptoInputStream(new ByteArrayInputStream(encData), cipher, defaultBufferSize, iv, withChannel)) {
buf = ByteBuffer.allocate(100);
byteBufferReadCheck(in, buf, 0);
}
// Default buffer size, initial buffer position is 0
- try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key,
- new IvParameterSpec(iv), withChannel)) {
+ try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key, new IvParameterSpec(iv), withChannel)) {
buf = ByteBuffer.allocate(dataLen + 100);
byteBufferReadCheck(in, buf, 0);
}
// Default buffer size, initial buffer position is not 0
- try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key,
- new IvParameterSpec(iv), withChannel)) {
+ try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key, new IvParameterSpec(iv), withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 11);
}
// Small buffer size, initial buffer position is 0
- try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key,
- new IvParameterSpec(iv), withChannel)) {
+ try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key, new IvParameterSpec(iv), withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 0);
}
// Small buffer size, initial buffer position is not 0
- try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key,
- new IvParameterSpec(iv), withChannel)) {
+ try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key, new IvParameterSpec(iv), withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 11);
}
// Direct buffer, default buffer size, initial buffer position is 0
- try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key,
- new IvParameterSpec(iv), withChannel)) {
+ try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key, new IvParameterSpec(iv), withChannel)) {
buf = ByteBuffer.allocateDirect(dataLen + 100);
byteBufferReadCheck(in, buf, 0);
}
// Direct buffer, default buffer size, initial buffer position is not 0
- try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key,
- new IvParameterSpec(iv), withChannel)) {
+ try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key, new IvParameterSpec(iv), withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 11);
}
// Direct buffer, small buffer size, initial buffer position is 0
- try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key,
- new IvParameterSpec(iv), withChannel)) {
+ try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key, new IvParameterSpec(iv), withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 0);
}
// Direct buffer, small buffer size, initial buffer position is not 0
- try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key,
- new IvParameterSpec(iv), withChannel)) {
+ try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key, new IvParameterSpec(iv), withChannel)) {
buf.clear();
byteBufferReadCheck(in, buf, 11);
}
// Direct buffer, default buffer size, initial buffer position is 0, final read
- try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key,
- new IvParameterSpec(iv), withChannel)) {
+ try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key, new IvParameterSpec(iv), withChannel)) {
buf.clear();
byteBufferFinalReadCheck(in, buf, 0);
}
// Default buffer size, initial buffer position is 0, insufficient dest buffer length
- try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key,
- new IvParameterSpec(iv), withChannel)) {
+ try (InputStream in = newCryptoInputStream(transformation, props, new ByteArrayInputStream(encData), key, new IvParameterSpec(iv), withChannel)) {
buf = ByteBuffer.allocate(100);
byteBufferReadCheck(in, buf, 0);
}
[commons-crypto] 04/08: Sort members
Posted by gg...@apache.org.
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 c32f6eb4abe448dffc7290a4098afd7a12cc7b66
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 22 09:04:44 2023 -0400
Sort members
---
.../crypto/random/CryptoRandomFactoryTest.java | 22 +++++++++++-----------
.../random/ExceptionInInitializerErrorRandom.java | 4 ++--
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java b/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java
index 4d18cad..4e20502 100644
--- a/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java
+++ b/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java
@@ -76,6 +76,17 @@ public class CryptoRandomFactoryTest {
CryptoRandomFactory.getCryptoRandom(properties).close();
}
+ @Test
+ public void testExceptionInInitializerErrorRandom() throws GeneralSecurityException, IOException {
+ final Properties properties = new Properties();
+ String classes = ExceptionInInitializerErrorRandom.class.getName().concat(",")
+ .concat(CryptoRandomFactory.RandomProvider.JAVA.getClassName());
+ properties.setProperty(CryptoRandomFactory.CLASSES_KEY, classes);
+ try (final CryptoRandom random = CryptoRandomFactory.getCryptoRandom(properties)) {
+ assertEquals(JavaCryptoRandom.class.getName(), random.getClass().getName());
+ }
+ }
+
@Test
public void testFailingRandom() {
final Properties properties = new Properties();
@@ -140,15 +151,4 @@ public class CryptoRandomFactoryTest {
public void testNull() {
assertThrows(NullPointerException.class, () -> CryptoRandomFactory.getCryptoRandom(null));
}
-
- @Test
- public void testExceptionInInitializerErrorRandom() throws GeneralSecurityException, IOException {
- final Properties properties = new Properties();
- String classes = ExceptionInInitializerErrorRandom.class.getName().concat(",")
- .concat(CryptoRandomFactory.RandomProvider.JAVA.getClassName());
- properties.setProperty(CryptoRandomFactory.CLASSES_KEY, classes);
- try (final CryptoRandom random = CryptoRandomFactory.getCryptoRandom(properties)) {
- assertEquals(JavaCryptoRandom.class.getName(), random.getClass().getName());
- }
- }
}
diff --git a/src/test/java/org/apache/commons/crypto/random/ExceptionInInitializerErrorRandom.java b/src/test/java/org/apache/commons/crypto/random/ExceptionInInitializerErrorRandom.java
index f44c98b..08bf012 100644
--- a/src/test/java/org/apache/commons/crypto/random/ExceptionInInitializerErrorRandom.java
+++ b/src/test/java/org/apache/commons/crypto/random/ExceptionInInitializerErrorRandom.java
@@ -38,12 +38,12 @@ public class ExceptionInInitializerErrorRandom implements CryptoRandom {
}
@Override
- public void nextBytes(byte[] bytes) {
+ public void close() throws IOException {
// empty
}
@Override
- public void close() throws IOException {
+ public void nextBytes(byte[] bytes) {
// empty
}
}