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 2020/06/06 23:33:01 UTC
[commons-crypto] 05/07: Remove trailing white space.
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 f6b718a50142b2156150281d70ebc1893d30ed1b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 6 19:27:13 2020 -0400
Remove trailing white space.
---
.../commons/crypto/jna/OpenSslJnaCipher.java | 4 +-
.../crypto/stream/AbstractCipherStreamTest.java | 112 ++++++++++-----------
.../commons/crypto/stream/CtrCryptoStreamTest.java | 50 ++++-----
.../stream/PositionedCryptoInputStreamTest.java | 12 +--
4 files changed, 89 insertions(+), 89 deletions(-)
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 1c68add..443a892 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
@@ -105,8 +105,8 @@ class OpenSslJnaCipher implements CryptoCipher {
throw new InvalidAlgorithmParameterException("Illegal parameters");
}
- if ((algMode == AlgorithmMode.AES_CBC ||
- algMode == AlgorithmMode.AES_CTR)
+ 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/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
index c9db8c4..9f4203e 100644
--- a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
@@ -103,7 +103,7 @@ public abstract class AbstractCipherStreamTest {
doByteBufferWrite(AbstractCipherTest.JCE_CIPHER_CLASSNAME, baos, true);
doByteBufferWrite(AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, baos, true);
}
-
+
@Test(timeout = 120000)
public void testExceptions() throws Exception {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -113,7 +113,7 @@ public abstract class AbstractCipherStreamTest {
doExceptionTest(AbstractCipherTest.JCE_CIPHER_CLASSNAME, baos, true);
doExceptionTest(AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, baos, true);
}
-
+
@Test(timeout = 120000)
public void testFieldGetters() throws Exception {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -138,7 +138,7 @@ public abstract class AbstractCipherStreamTest {
final int n1 = readAll(in, result, 0, dataLen / 5);
Assert.assertEquals(in.skip(0), 0);
-
+
long skipped = in.skip(dataLen / 5);
final int n2 = readAll(in, result, 0, dataLen);
@@ -311,7 +311,7 @@ public abstract class AbstractCipherStreamTest {
}
protected void doByteBufferWrite(final String cipherClass,
- final ByteArrayOutputStream baos, final boolean withChannel)
+ final ByteArrayOutputStream baos, final boolean withChannel)
throws Exception {
if (AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME.equals(cipherClass)) {
if (!Crypto.isNativeCodeLoaded()) {
@@ -322,17 +322,17 @@ public abstract class AbstractCipherStreamTest {
CryptoOutputStream out = getCryptoOutputStream(baos,
getCipher(cipherClass), defaultBufferSize, iv, withChannel);
doByteBufferWrite(out, withChannel);
-
+
baos.reset();
CryptoCipher cipher = getCipher(cipherClass);
String transformation = cipher.getAlgorithm();
- out = getCryptoOutputStream(transformation, props, baos, key,
+ out = getCryptoOutputStream(transformation, props, baos, key,
new IvParameterSpec(iv), withChannel);
doByteBufferWrite(out, withChannel);
out.write(1);
- Assert.assertTrue(out.isOpen());
-
- out = getCryptoOutputStream(transformation, props, baos, key,
+ Assert.assertTrue(out.isOpen());
+
+ out = getCryptoOutputStream(transformation, props, baos, key,
new IvParameterSpec(iv), withChannel);
out.close();
Assert.assertTrue(!out.isOpen());
@@ -345,84 +345,84 @@ public abstract class AbstractCipherStreamTest {
return; // Skip this test if no JNI
}
}
-
+
InputStream in = null;
OutputStream out = null;
-
+
// Test InvalidAlgorithmParameters
try {
- in = getCryptoInputStream(transformation, props, new ByteArrayInputStream(encData),
- new SecretKeySpec(key, "AES"), new GCMParameterSpec(0, new byte[0]),
+ in = getCryptoInputStream(transformation, props, new ByteArrayInputStream(encData),
+ new SecretKeySpec(key, "AES"), new GCMParameterSpec(0, new byte[0]),
withChannel);
Assert.fail("Expected IOException.");
} catch (IOException ex) {
Assert.assertEquals(ex.getMessage(),"Illegal parameters");
- }
-
+ }
+
// Test InvalidAlgorithmParameters
try {
- out = getCryptoOutputStream(transformation, props, baos,
- new SecretKeySpec(key, "AES"), new GCMParameterSpec(0,
+ out = getCryptoOutputStream(transformation, props, baos,
+ new SecretKeySpec(key, "AES"), new GCMParameterSpec(0,
new byte[0]), withChannel);
Assert.fail("Expected IOException.");
} catch (IOException ex) {
Assert.assertEquals(ex.getMessage(),"Illegal parameters");
- }
-
+ }
+
// Test Invalid Key
try {
- in = getCryptoInputStream(transformation,props, new ByteArrayInputStream(encData),
+ in = getCryptoInputStream(transformation,props, new ByteArrayInputStream(encData),
new SecretKeySpec(new byte[10], "AES"), new IvParameterSpec(iv), withChannel);
Assert.fail("Expected IOException for Invalid Key");
} catch (IOException ex) {
Assert.assertNotNull(ex);
}
-
+
// Test Invalid Key
try {
- out = getCryptoOutputStream(transformation, props, baos, new byte[10],
+ out = getCryptoOutputStream(transformation, props, baos, new byte[10],
new IvParameterSpec(iv), withChannel);
Assert.fail("Expected IOException for Invalid Key");
} catch (IOException ex) {
Assert.assertNotNull(ex);
}
-
+
// Test reading a closed stream.
- try {
- in = getCryptoInputStream(new ByteArrayInputStream(encData),
+ try {
+ in = getCryptoInputStream(new ByteArrayInputStream(encData),
getCipher(cipherClass), defaultBufferSize, iv, withChannel);
in.close();
in.read(); // Throw exception.
} catch (IOException ex) {
Assert.assertTrue(ex.getMessage().equals("Stream closed"));
- }
-
+ }
+
// Test closing a closed stream.
- try {
+ try {
in.close(); // Don't throw exception on double-close.
} catch (IOException ex) {
Assert.fail("Should not throw exception closing a closed stream.");
- }
+ }
// Test checking a closed stream.
- try {
- out = getCryptoOutputStream(transformation, props, baos, key, new IvParameterSpec(iv),
+ try {
+ out = getCryptoOutputStream(transformation, props, baos, key, new IvParameterSpec(iv),
withChannel);
out.close();
((CryptoOutputStream)out).checkStream(); // Throw exception.
} catch (IOException ex) {
Assert.assertTrue(ex.getMessage().equals("Stream closed"));
- }
+ }
// Test closing a closed stream.
- try {
+ try {
out.close(); // Don't throw exception.
} catch (IOException ex) {
Assert.fail("Should not throw exception closing a closed stream.");
- }
-
+ }
+
// Test checkStreamCipher
- try {
+ try {
CryptoInputStream.checkStreamCipher(getCipher(cipherClass));
} catch (IOException ex) {
Assert.assertTrue(ex.getMessage().equals("AES/CTR/NoPadding is required"));
@@ -431,8 +431,8 @@ public abstract class AbstractCipherStreamTest {
}
// Test unsupported operation handling.
- try {
- in = getCryptoInputStream(new ByteArrayInputStream(encData),
+ try {
+ in = getCryptoInputStream(new ByteArrayInputStream(encData),
getCipher(cipherClass), defaultBufferSize, iv, false);
in.mark(0);
assertEquals(false, in.markSupported());
@@ -452,12 +452,12 @@ public abstract class AbstractCipherStreamTest {
return; // Skip this test if no JNI
}
}
-
+
CryptoCipher cipher = getCipher(cipherClass);
-
+
CryptoInputStream in = getCryptoInputStream(
- new ByteArrayInputStream(encData), cipher, defaultBufferSize,
- iv, withChannel);
+ new ByteArrayInputStream(encData), cipher, defaultBufferSize,
+ iv, withChannel);
Properties props = new Properties();
String bufferSize = Integer.toString(defaultBufferSize / 2);
@@ -470,14 +470,14 @@ public abstract class AbstractCipherStreamTest {
Assert.assertEquals(in.getParams().getClass(), IvParameterSpec.class);
Assert.assertNotNull(in.getInput());
- CryptoOutputStream out = getCryptoOutputStream(baos, getCipher(cipherClass),
+ CryptoOutputStream out = getCryptoOutputStream(baos, getCipher(cipherClass),
defaultBufferSize, iv, withChannel);
Assert.assertEquals(out.getOutBuffer().capacity(), defaultBufferSize + cipher.getBlockSize());
Assert.assertEquals(out.getInBuffer().capacity(), defaultBufferSize);
Assert.assertEquals(out.getBufferSize(), defaultBufferSize);
}
-
+
private void byteBufferReadCheck(final InputStream in, final ByteBuffer buf, final int bufPos)
throws Exception {
buf.position(bufPos);
@@ -535,7 +535,7 @@ public abstract class AbstractCipherStreamTest {
}
encData = baos.toByteArray();
}
-
+
private void doByteBufferWrite(CryptoOutputStream out, boolean withChannel) throws Exception {
ByteBuffer buf = ByteBuffer.allocateDirect(dataLen / 2);
buf.put(data, 0, dataLen / 2);
@@ -551,18 +551,18 @@ public abstract class AbstractCipherStreamTest {
buf.put(data, n1 + n2, dataLen - n1 - n2 - 1);
buf.flip();
final int n3 = out.write(buf);
-
+
out.write(1);
Assert.assertEquals(dataLen, n1 + n2 + n3 + 1);
-
+
try {
out.write(data, 0, data.length + 1);
Assert.fail("Expected IndexOutOfBoundsException.");
} catch (IndexOutOfBoundsException ex) {
Assert.assertNotNull(ex);
}
-
+
out.flush();
try (InputStream in = getCryptoInputStream(
@@ -584,8 +584,8 @@ public abstract class AbstractCipherStreamTest {
return new CryptoInputStream(bais, cipher, bufferSize,
new SecretKeySpec(key, "AES"), new IvParameterSpec(iv));
}
-
- protected CryptoInputStream getCryptoInputStream(final String transformation, final Properties props,
+
+ protected CryptoInputStream getCryptoInputStream(final String transformation, final Properties props,
final ByteArrayInputStream bais, final byte[] key, final AlgorithmParameterSpec params,
boolean withChannel) throws IOException {
if (withChannel) {
@@ -593,7 +593,7 @@ public abstract class AbstractCipherStreamTest {
}
return new CryptoInputStream(transformation, props, bais, new SecretKeySpec(key, "AES"), params);
}
-
+
protected CryptoInputStream getCryptoInputStream(final String transformation,
final Properties props, final ByteArrayInputStream bais, final Key key,
final AlgorithmParameterSpec params, boolean withChannel) throws IOException {
@@ -614,18 +614,18 @@ public abstract class AbstractCipherStreamTest {
return new CryptoOutputStream(baos, cipher, bufferSize,
new SecretKeySpec(key, "AES"), new IvParameterSpec(iv));
}
-
+
protected CryptoOutputStream getCryptoOutputStream(final String transformation,
- final Properties props, final ByteArrayOutputStream baos, final byte[] key,
+ final Properties props, final ByteArrayOutputStream baos, final byte[] key,
final AlgorithmParameterSpec param, final boolean withChannel) throws IOException {
if (withChannel) {
- return new CryptoOutputStream(transformation, props, Channels.newChannel(baos),
+ return new CryptoOutputStream(transformation, props, Channels.newChannel(baos),
new SecretKeySpec(key, "AES"), param);
}
- return new CryptoOutputStream(transformation, props, baos, new SecretKeySpec(key, "AES"),
+ return new CryptoOutputStream(transformation, props, baos, new SecretKeySpec(key, "AES"),
param);
}
-
+
protected CryptoOutputStream getCryptoOutputStream(final String transformation,
final Properties props, final ByteArrayOutputStream baos, final Key key,
final AlgorithmParameterSpec params, boolean withChannel) throws IOException {
diff --git a/src/test/java/org/apache/commons/crypto/stream/CtrCryptoStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/CtrCryptoStreamTest.java
index 22e16e9..5d7d14e 100644
--- a/src/test/java/org/apache/commons/crypto/stream/CtrCryptoStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/CtrCryptoStreamTest.java
@@ -53,13 +53,13 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest {
}
return new CtrCryptoInputStream(bais, cipher, bufferSize, key, iv);
}
-
+
@Override
- protected CtrCryptoInputStream getCryptoInputStream(final String transformation, final Properties props,
+ protected CtrCryptoInputStream getCryptoInputStream(final String transformation, final Properties props,
final ByteArrayInputStream bais, final byte[] key, final AlgorithmParameterSpec params,
boolean withChannel) throws IOException {
if (withChannel) {
- return new CtrCryptoInputStream(props, Channels.newChannel(bais), key,
+ return new CtrCryptoInputStream(props, Channels.newChannel(bais), key,
((IvParameterSpec)params).getIV());
}
return new CtrCryptoInputStream(props, bais, key, ((IvParameterSpec)params).getIV());
@@ -75,18 +75,18 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest {
}
return new CtrCryptoOutputStream(baos, cipher, bufferSize, key, iv);
}
-
+
@Override
protected CtrCryptoOutputStream getCryptoOutputStream(final String transformation,
- final Properties props, final ByteArrayOutputStream baos, final byte[] key,
+ final Properties props, final ByteArrayOutputStream baos, final byte[] key,
final AlgorithmParameterSpec params, final boolean withChannel) throws IOException {
if (withChannel) {
- return new CtrCryptoOutputStream(props, Channels.newChannel(baos), key,
+ return new CtrCryptoOutputStream(props, Channels.newChannel(baos), key,
((IvParameterSpec)params).getIV());
}
return new CtrCryptoOutputStream(props, baos, key, ((IvParameterSpec)params).getIV());
}
-
+
@Override
protected void doFieldGetterTest(final String cipherClass, final ByteArrayOutputStream baos,
final boolean withChannel) throws Exception {
@@ -95,7 +95,7 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest {
return; // Skip this test if no JNI
}
}
-
+
StreamInput streamInput = new StreamInput(new ByteArrayInputStream(encData), 0);
try {
streamInput.seek(0);
@@ -110,7 +110,7 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest {
Assert.assertEquals(ex.getMessage(), "Positioned read is not supported by this implementation");
}
Assert.assertEquals(streamInput.available(), encData.length);
-
+
ChannelInput channelInput = new ChannelInput(Channels.newChannel(new ByteArrayInputStream(encData)));
try {
channelInput.seek(0);
@@ -125,15 +125,15 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest {
Assert.assertEquals(ex.getMessage(), "Positioned read is not supported by this implementation");
}
Assert.assertEquals(channelInput.available(), 0);
-
- CtrCryptoInputStream in = new CtrCryptoInputStream(channelInput, getCipher(cipherClass),
+
+ CtrCryptoInputStream in = new CtrCryptoInputStream(channelInput, getCipher(cipherClass),
defaultBufferSize, key, iv);
-
+
Properties props = new Properties();
String bufferSize = "4096";
props.put(CryptoInputStream.STREAM_BUFFER_SIZE_KEY, bufferSize);
in.setStreamOffset(smallBufferSize);
-
+
Assert.assertEquals(CryptoInputStream.getBufferSize(props), Integer.parseInt(bufferSize));
Assert.assertEquals(smallBufferSize, in.getStreamOffset());
Assert.assertEquals(in.getBufferSize(), 8192);
@@ -141,18 +141,18 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest {
Assert.assertEquals(in.getKey().getAlgorithm(), "AES");
Assert.assertEquals(in.getParams().getClass(), IvParameterSpec.class);
Assert.assertNotNull(in.getInput());
-
+
in.close();
-
+
CtrCryptoOutputStream out = new CtrCryptoOutputStream(new ChannelOutput(
- Channels.newChannel(baos)), getCipher(cipherClass),
+ Channels.newChannel(baos)), getCipher(cipherClass),
Integer.parseInt(bufferSize), key, iv);
out.setStreamOffset(smallBufferSize);
Assert.assertEquals(out.getStreamOffset(), smallBufferSize);
-
+
out.close();
}
-
+
@Test(timeout = 120000)
public void testDecrypt() throws Exception {
doDecryptTest(AbstractCipherTest.JCE_CIPHER_CLASSNAME, false);
@@ -161,13 +161,13 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest {
doDecryptTest(AbstractCipherTest.JCE_CIPHER_CLASSNAME, true);
doDecryptTest(AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, true);
}
-
+
protected void doDecryptTest(final String cipherClass, final boolean withChannel)
throws IOException {
-
- CtrCryptoInputStream in = getCryptoInputStream(new ByteArrayInputStream(encData),
+
+ CtrCryptoInputStream in = getCryptoInputStream(new ByteArrayInputStream(encData),
getCipher(cipherClass), defaultBufferSize, iv, withChannel);
-
+
ByteBuffer buf = ByteBuffer.allocateDirect(dataLen);
buf.put(encData);
buf.rewind();
@@ -177,13 +177,13 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest {
buf.get(readData);
System.arraycopy(data, 0, expectedData, 0, dataLen);
Assert.assertArrayEquals(readData, expectedData);
-
+
try {
in.decryptBuffer(buf);
Assert.fail("Expected IOException.");
} catch (IOException ex) {
- Assert.assertEquals(ex.getCause().getClass(), ShortBufferException.class);
+ Assert.assertEquals(ex.getCause().getClass(), ShortBufferException.class);
}
-
+
}
}
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 6293720..1e7ee15 100644
--- a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
@@ -93,8 +93,8 @@ public class PositionedCryptoInputStreamTest {
Arrays.copyOf(encData, encData.length)), cipher, bufferSize,
key, iv, 0);
}
-
- private PositionedCryptoInputStream getCryptoInputStream(final int streamOffset)
+
+ private PositionedCryptoInputStream getCryptoInputStream(final int streamOffset)
throws IOException {
return new PositionedCryptoInputStream(props, new PositionedInputForTest(
Arrays.copyOf(encData, encData.length)), key, iv, streamOffset);
@@ -154,7 +154,7 @@ public class PositionedCryptoInputStreamTest {
}
}
}
-
+
private void doMultipleReadTest() throws Exception{
PositionedCryptoInputStream in = getCryptoInputStream(0);
final String cipherClass = in.getCipher().getClass().getName();
@@ -177,7 +177,7 @@ public class PositionedCryptoInputStreamTest {
testPositionedReadNone(cipherClass, -1, length, bufferSize);
testPositionedReadNone(cipherClass, dataLen, length, bufferSize);
}
-
+
private void doPositionedReadTests() throws Exception {
PositionedCryptoInputStream in = getCryptoInputStream(0);
final String cipherClass = in.getCipher().getClass().getName();
@@ -199,7 +199,7 @@ public class PositionedCryptoInputStreamTest {
testReadFullyFailed(cipherClass, dataLen - length + 1, length,
bufferSize);
}
-
+
private void doReadFullyTests() throws Exception {
PositionedCryptoInputStream in = getCryptoInputStream(0);
final String cipherClass = in.getCipher().getClass().getName();
@@ -216,7 +216,7 @@ public class PositionedCryptoInputStreamTest {
// test exception when position = -1
testSeekFailed(cipherClass, -1, bufferSize);
}
-
+
private void doSeekTests() throws Exception{
PositionedCryptoInputStream in = getCryptoInputStream(0);
final String cipherClass = in.getCipher().getClass().getName();