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 521aac8c35241601ed70886f7f59a95ab8b02ab1 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Jun 6 19:28:03 2020 -0400 Use final. --- .../commons/crypto/cipher/AbstractCipherTest.java | 6 +-- .../crypto/stream/AbstractCipherStreamTest.java | 52 +++++++++++----------- .../commons/crypto/stream/CtrCryptoStreamTest.java | 32 ++++++------- .../stream/PositionedCryptoInputStreamTest.java | 8 ++-- 4 files changed, 49 insertions(+), 49 deletions(-) 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 3ae06a0..ca27546 100644 --- a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java +++ b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java @@ -163,7 +163,7 @@ public abstract class AbstractCipherTest { @Test public void testInvalidKey() throws Exception { - for (String transform : transformations) { + for (final String transform : transformations) { try { final CryptoCipher cipher = getCipher(transform); Assert.assertNotNull(cipher); @@ -179,7 +179,7 @@ public abstract class AbstractCipherTest { @Test public void testInvalidIV() throws Exception { - for (String transform : transformations) { + for (final String transform : transformations) { try { final CryptoCipher cipher = getCipher(transform); Assert.assertNotNull(cipher); @@ -195,7 +195,7 @@ public abstract class AbstractCipherTest { @Test public void testInvalidIVClass() throws Exception { - for (String transform : transformations) { + for (final String transform : transformations) { try { final CryptoCipher cipher = getCipher(transform); Assert.assertNotNull(cipher); 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 9f4203e..f71c6df 100644 --- a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java +++ b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java @@ -324,8 +324,8 @@ public abstract class AbstractCipherStreamTest { doByteBufferWrite(out, withChannel); baos.reset(); - CryptoCipher cipher = getCipher(cipherClass); - String transformation = cipher.getAlgorithm(); + final CryptoCipher cipher = getCipher(cipherClass); + final String transformation = cipher.getAlgorithm(); out = getCryptoOutputStream(transformation, props, baos, key, new IvParameterSpec(iv), withChannel); doByteBufferWrite(out, withChannel); @@ -338,7 +338,7 @@ public abstract class AbstractCipherStreamTest { Assert.assertTrue(!out.isOpen()); } - protected void doExceptionTest(final String cipherClass, ByteArrayOutputStream baos, + protected void doExceptionTest(final String cipherClass, final ByteArrayOutputStream baos, final boolean withChannel) throws IOException { if (AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME.equals(cipherClass)) { if (!Crypto.isNativeCodeLoaded()) { @@ -355,7 +355,7 @@ public abstract class AbstractCipherStreamTest { new SecretKeySpec(key, "AES"), new GCMParameterSpec(0, new byte[0]), withChannel); Assert.fail("Expected IOException."); - } catch (IOException ex) { + } catch (final IOException ex) { Assert.assertEquals(ex.getMessage(),"Illegal parameters"); } @@ -365,7 +365,7 @@ public abstract class AbstractCipherStreamTest { new SecretKeySpec(key, "AES"), new GCMParameterSpec(0, new byte[0]), withChannel); Assert.fail("Expected IOException."); - } catch (IOException ex) { + } catch (final IOException ex) { Assert.assertEquals(ex.getMessage(),"Illegal parameters"); } @@ -374,7 +374,7 @@ public abstract class AbstractCipherStreamTest { 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) { + } catch (final IOException ex) { Assert.assertNotNull(ex); } @@ -383,7 +383,7 @@ public abstract class AbstractCipherStreamTest { out = getCryptoOutputStream(transformation, props, baos, new byte[10], new IvParameterSpec(iv), withChannel); Assert.fail("Expected IOException for Invalid Key"); - } catch (IOException ex) { + } catch (final IOException ex) { Assert.assertNotNull(ex); } @@ -393,14 +393,14 @@ public abstract class AbstractCipherStreamTest { getCipher(cipherClass), defaultBufferSize, iv, withChannel); in.close(); in.read(); // Throw exception. - } catch (IOException ex) { + } catch (final IOException ex) { Assert.assertTrue(ex.getMessage().equals("Stream closed")); } // Test closing a closed stream. try { in.close(); // Don't throw exception on double-close. - } catch (IOException ex) { + } catch (final IOException ex) { Assert.fail("Should not throw exception closing a closed stream."); } @@ -410,21 +410,21 @@ public abstract class AbstractCipherStreamTest { withChannel); out.close(); ((CryptoOutputStream)out).checkStream(); // Throw exception. - } catch (IOException ex) { + } catch (final IOException ex) { Assert.assertTrue(ex.getMessage().equals("Stream closed")); } // Test closing a closed stream. try { out.close(); // Don't throw exception. - } catch (IOException ex) { + } catch (final IOException ex) { Assert.fail("Should not throw exception closing a closed stream."); } // Test checkStreamCipher try { CryptoInputStream.checkStreamCipher(getCipher(cipherClass)); - } catch (IOException ex) { + } catch (final IOException ex) { Assert.assertTrue(ex.getMessage().equals("AES/CTR/NoPadding is required")); } finally { in.close(); @@ -438,14 +438,14 @@ public abstract class AbstractCipherStreamTest { assertEquals(false, in.markSupported()); in.reset(); Assert.fail("Expected IOException."); - } catch (IOException ex) { + } catch (final IOException ex) { Assert.assertTrue(ex.getMessage().equals("Mark/reset not supported")); } finally { in.close(); } } - protected void doFieldGetterTest(final String cipherClass, ByteArrayOutputStream baos, + protected void doFieldGetterTest(final String cipherClass, final ByteArrayOutputStream baos, final boolean withChannel) throws Exception { if (AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME.equals(cipherClass)) { if (!Crypto.isNativeCodeLoaded()) { @@ -453,14 +453,14 @@ public abstract class AbstractCipherStreamTest { } } - CryptoCipher cipher = getCipher(cipherClass); + final CryptoCipher cipher = getCipher(cipherClass); - CryptoInputStream in = getCryptoInputStream( + final CryptoInputStream in = getCryptoInputStream( new ByteArrayInputStream(encData), cipher, defaultBufferSize, iv, withChannel); - Properties props = new Properties(); - String bufferSize = Integer.toString(defaultBufferSize / 2); + final Properties props = new Properties(); + final String bufferSize = Integer.toString(defaultBufferSize / 2); props.put(CryptoInputStream.STREAM_BUFFER_SIZE_KEY, bufferSize); Assert.assertEquals(CryptoInputStream.getBufferSize(props), Integer.parseInt(bufferSize)); @@ -470,7 +470,7 @@ public abstract class AbstractCipherStreamTest { Assert.assertEquals(in.getParams().getClass(), IvParameterSpec.class); Assert.assertNotNull(in.getInput()); - CryptoOutputStream out = getCryptoOutputStream(baos, getCipher(cipherClass), + final CryptoOutputStream out = getCryptoOutputStream(baos, getCipher(cipherClass), defaultBufferSize, iv, withChannel); Assert.assertEquals(out.getOutBuffer().capacity(), defaultBufferSize + cipher.getBlockSize()); @@ -494,7 +494,7 @@ public abstract class AbstractCipherStreamTest { try { in.read(readData, -1, 0); Assert.fail("Expected IndexOutOfBoundsException."); - } catch (IndexOutOfBoundsException ex) { + } catch (final IndexOutOfBoundsException ex) { Assert.assertNotNull(ex); } } @@ -509,7 +509,7 @@ public abstract class AbstractCipherStreamTest { len += n; } while (n > 0); buf.rewind(); - byte[] readData = new byte[len + 1]; + final byte[] readData = new byte[len + 1]; buf.get(readData); final byte[] expectedData = new byte[len + 1]; System.arraycopy(data, 0, expectedData, 0, len + 1); @@ -536,7 +536,7 @@ public abstract class AbstractCipherStreamTest { encData = baos.toByteArray(); } - private void doByteBufferWrite(CryptoOutputStream out, boolean withChannel) throws Exception { + private void doByteBufferWrite(final CryptoOutputStream out, final boolean withChannel) throws Exception { ByteBuffer buf = ByteBuffer.allocateDirect(dataLen / 2); buf.put(data, 0, dataLen / 2); buf.flip(); @@ -559,7 +559,7 @@ public abstract class AbstractCipherStreamTest { try { out.write(data, 0, data.length + 1); Assert.fail("Expected IndexOutOfBoundsException."); - } catch (IndexOutOfBoundsException ex) { + } catch (final IndexOutOfBoundsException ex) { Assert.assertNotNull(ex); } @@ -587,7 +587,7 @@ public abstract class AbstractCipherStreamTest { protected CryptoInputStream getCryptoInputStream(final String transformation, final Properties props, final ByteArrayInputStream bais, final byte[] key, final AlgorithmParameterSpec params, - boolean withChannel) throws IOException { + final boolean withChannel) throws IOException { if (withChannel) { return new CryptoInputStream(transformation, props, Channels.newChannel(bais), new SecretKeySpec(key, "AES"), params); } @@ -596,7 +596,7 @@ public abstract class AbstractCipherStreamTest { protected CryptoInputStream getCryptoInputStream(final String transformation, final Properties props, final ByteArrayInputStream bais, final Key key, - final AlgorithmParameterSpec params, boolean withChannel) throws IOException { + final AlgorithmParameterSpec params, final boolean withChannel) throws IOException { if (withChannel) { return new CryptoInputStream(transformation, props, Channels.newChannel(bais), key, params); } @@ -628,7 +628,7 @@ public abstract class AbstractCipherStreamTest { protected CryptoOutputStream getCryptoOutputStream(final String transformation, final Properties props, final ByteArrayOutputStream baos, final Key key, - final AlgorithmParameterSpec params, boolean withChannel) throws IOException { + final AlgorithmParameterSpec params, final boolean withChannel) throws IOException { if (withChannel) { return new CryptoOutputStream(transformation, props, Channels.newChannel(baos), key, params); } 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 5d7d14e..d37a5d4 100644 --- a/src/test/java/org/apache/commons/crypto/stream/CtrCryptoStreamTest.java +++ b/src/test/java/org/apache/commons/crypto/stream/CtrCryptoStreamTest.java @@ -57,7 +57,7 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest { @Override protected CtrCryptoInputStream getCryptoInputStream(final String transformation, final Properties props, final ByteArrayInputStream bais, final byte[] key, final AlgorithmParameterSpec params, - boolean withChannel) throws IOException { + final boolean withChannel) throws IOException { if (withChannel) { return new CtrCryptoInputStream(props, Channels.newChannel(bais), key, ((IvParameterSpec)params).getIV()); @@ -96,41 +96,41 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest { } } - StreamInput streamInput = new StreamInput(new ByteArrayInputStream(encData), 0); + final StreamInput streamInput = new StreamInput(new ByteArrayInputStream(encData), 0); try { streamInput.seek(0); Assert.fail("Expected UnsupportedOperationException."); - } catch (UnsupportedOperationException ex) { + } catch (final UnsupportedOperationException ex) { Assert.assertEquals(ex.getMessage(), "Seek is not supported by this implementation"); } try { streamInput.read(0, new byte[0], 0, 0); Assert.fail("Expected UnsupportedOperationException."); - } catch (UnsupportedOperationException ex) { + } catch (final UnsupportedOperationException ex) { 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))); + final ChannelInput channelInput = new ChannelInput(Channels.newChannel(new ByteArrayInputStream(encData))); try { channelInput.seek(0); Assert.fail("Expected UnsupportedOperationException."); - } catch (UnsupportedOperationException ex) { + } catch (final UnsupportedOperationException ex) { Assert.assertEquals(ex.getMessage(), "Seek is not supported by this implementation"); } try { channelInput.read(0, new byte[0], 0, 0); Assert.fail("Expected UnsupportedOperationException."); - } catch (UnsupportedOperationException ex) { + } catch (final UnsupportedOperationException ex) { Assert.assertEquals(ex.getMessage(), "Positioned read is not supported by this implementation"); } Assert.assertEquals(channelInput.available(), 0); - CtrCryptoInputStream in = new CtrCryptoInputStream(channelInput, getCipher(cipherClass), + final CtrCryptoInputStream in = new CtrCryptoInputStream(channelInput, getCipher(cipherClass), defaultBufferSize, key, iv); - Properties props = new Properties(); - String bufferSize = "4096"; + final Properties props = new Properties(); + final String bufferSize = "4096"; props.put(CryptoInputStream.STREAM_BUFFER_SIZE_KEY, bufferSize); in.setStreamOffset(smallBufferSize); @@ -144,7 +144,7 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest { in.close(); - CtrCryptoOutputStream out = new CtrCryptoOutputStream(new ChannelOutput( + final CtrCryptoOutputStream out = new CtrCryptoOutputStream(new ChannelOutput( Channels.newChannel(baos)), getCipher(cipherClass), Integer.parseInt(bufferSize), key, iv); out.setStreamOffset(smallBufferSize); @@ -165,15 +165,15 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest { protected void doDecryptTest(final String cipherClass, final boolean withChannel) throws IOException { - CtrCryptoInputStream in = getCryptoInputStream(new ByteArrayInputStream(encData), + final CtrCryptoInputStream in = getCryptoInputStream(new ByteArrayInputStream(encData), getCipher(cipherClass), defaultBufferSize, iv, withChannel); - ByteBuffer buf = ByteBuffer.allocateDirect(dataLen); + final ByteBuffer buf = ByteBuffer.allocateDirect(dataLen); buf.put(encData); buf.rewind(); in.decrypt(buf, 0, dataLen); - byte[] readData = new byte[dataLen]; - byte[] expectedData = new byte[dataLen]; + final byte[] readData = new byte[dataLen]; + final byte[] expectedData = new byte[dataLen]; buf.get(readData); System.arraycopy(data, 0, expectedData, 0, dataLen); Assert.assertArrayEquals(readData, expectedData); @@ -181,7 +181,7 @@ public class CtrCryptoStreamTest extends AbstractCipherStreamTest { try { in.decryptBuffer(buf); Assert.fail("Expected IOException."); - } catch (IOException ex) { + } catch (final IOException ex) { 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 1e7ee15..825b00e 100644 --- a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java +++ b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java @@ -156,7 +156,7 @@ public class PositionedCryptoInputStreamTest { } private void doMultipleReadTest() throws Exception{ - PositionedCryptoInputStream in = getCryptoInputStream(0); + final PositionedCryptoInputStream in = getCryptoInputStream(0); final String cipherClass = in.getCipher().getClass().getName(); doMultipleReadTest(cipherClass); } @@ -179,7 +179,7 @@ public class PositionedCryptoInputStreamTest { } private void doPositionedReadTests() throws Exception { - PositionedCryptoInputStream in = getCryptoInputStream(0); + final PositionedCryptoInputStream in = getCryptoInputStream(0); final String cipherClass = in.getCipher().getClass().getName(); doPositionedReadTests(cipherClass); } @@ -201,7 +201,7 @@ public class PositionedCryptoInputStreamTest { } private void doReadFullyTests() throws Exception { - PositionedCryptoInputStream in = getCryptoInputStream(0); + final PositionedCryptoInputStream in = getCryptoInputStream(0); final String cipherClass = in.getCipher().getClass().getName(); doReadFullyTests(cipherClass); } @@ -218,7 +218,7 @@ public class PositionedCryptoInputStreamTest { } private void doSeekTests() throws Exception{ - PositionedCryptoInputStream in = getCryptoInputStream(0); + final PositionedCryptoInputStream in = getCryptoInputStream(0); final String cipherClass = in.getCipher().getClass().getName(); doSeekTests(cipherClass); }