diff --git a/test/freenet/crypt/CTRBlockCipherTest.java b/test/freenet/crypt/CTRBlockCipherTest.java index 51c4e17478..60b7ee3ea7 100644 --- a/test/freenet/crypt/CTRBlockCipherTest.java +++ b/test/freenet/crypt/CTRBlockCipherTest.java @@ -1,11 +1,11 @@ package freenet.crypt; -import static org.junit.Assert.*; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; -import java.util.Arrays; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; @@ -183,7 +183,7 @@ private void checkNIST(int bits, byte[] key, byte[] iv, byte[] plaintext, Cipher c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider); c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv)); byte[] output = c.doFinal(plaintext); - assertTrue(Arrays.equals(output, ciphertext)); + assertThat(output, equalTo(ciphertext)); } Rijndael cipher = new Rijndael(bits, 128); @@ -192,7 +192,7 @@ private void checkNIST(int bits, byte[] key, byte[] iv, byte[] plaintext, ctr.init(iv); byte[] output = new byte[plaintext.length]; ctr.processBytes(plaintext, 0, plaintext.length, output, 0); - assertTrue(Arrays.equals(output, ciphertext)); + assertThat(output, equalTo(ciphertext)); } private void checkNISTRandomLength(int bits, byte[] key, byte[] iv, @@ -226,7 +226,7 @@ private void checkNISTRandomLength(int bits, byte[] key, byte[] iv, } c.doFinal(plaintext, 0, plaintext.length - inputPtr, output, outputPtr); - assertTrue(Arrays.equals(output, ciphertext)); + assertThat(output, equalTo(ciphertext)); } Rijndael cipher = new Rijndael(bits, 128); @@ -242,7 +242,7 @@ private void checkNISTRandomLength(int bits, byte[] key, byte[] iv, ctr.processBytes(plaintext, ptr, count, output, ptr); ptr += count; } - assertTrue(Arrays.equals(output, ciphertext)); + assertThat(output, equalTo(ciphertext)); } } @@ -263,7 +263,7 @@ public void testRandomJCA() throws NoSuchAlgorithmException, NoSuchPaddingExcept c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider); c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv)); byte[] decrypted = c.doFinal(output); - assertTrue(Arrays.equals(decrypted, plaintext)); + assertThat(decrypted, equalTo(plaintext)); } } @@ -288,17 +288,17 @@ public void testRandom() throws UnsupportedCipherException, NoSuchAlgorithmExcep ctr.init(iv); byte[] finalPlaintext = new byte[plaintext.length]; ctr.processBytes(ciphertext, 0, ciphertext.length, finalPlaintext, 0); - assertTrue(Arrays.equals(finalPlaintext, plaintext)); + assertThat(finalPlaintext, equalTo(plaintext)); if(TEST_JCA) { SecretKeySpec k = new SecretKeySpec(key, "AES"); Cipher c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider); c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv)); byte[] output = c.doFinal(plaintext); - assertTrue(Arrays.equals(output, ciphertext)); + assertThat(output, equalTo(ciphertext)); c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider); c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv)); byte[] decrypted = c.doFinal(output); - assertTrue(Arrays.equals(decrypted, plaintext)); + assertThat(decrypted, equalTo(plaintext)); } // Now encrypt again, in random pieces. cipher.initialize(key); @@ -313,7 +313,7 @@ public void testRandom() throws UnsupportedCipherException, NoSuchAlgorithmExcep ctr.processBytes(plaintext, ptr, count, output, ptr); ptr += count; } - assertTrue(Arrays.equals(output, ciphertext)); + assertThat(output, equalTo(ciphertext)); } } diff --git a/test/freenet/crypt/CryptByteBufferTest.java b/test/freenet/crypt/CryptByteBufferTest.java index b4040b5ef4..46e56fee30 100755 --- a/test/freenet/crypt/CryptByteBufferTest.java +++ b/test/freenet/crypt/CryptByteBufferTest.java @@ -3,11 +3,13 @@ * http://www.gnu.org/ for further details of the GPL. */ package freenet.crypt; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.nio.ByteBuffer; @@ -95,11 +97,13 @@ public void testRoundOneByte() throws GeneralSecurityException { byte[] buf = origPlaintext.clone(); for(int j=0;j