You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2006/04/20 05:49:34 UTC
svn commit: r395473 -
/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/tests/api/javax/crypto/CipherTest.java
Author: smishura
Date: Wed Apr 19 20:49:33 2006
New Revision: 395473
URL: http://svn.apache.org/viewcvs?rev=395473&view=rev
Log:
Utilizing JUnit's exception handling for 2 tests
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/tests/api/javax/crypto/CipherTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/tests/api/javax/crypto/CipherTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/tests/api/javax/crypto/CipherTest.java?rev=395473&r1=395472&r2=395473&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/tests/api/javax/crypto/CipherTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/tests/api/javax/crypto/CipherTest.java Wed Apr 19 20:49:33 2006
@@ -475,117 +475,99 @@
/**
* @tests javax.crypto.Cipher#update(byte[], int, int)
*/
- public void test_update$BII() {
- try {
- for (int index = 1; index < 4; index++) {
- Cipher c = null;
- try {
- c = Cipher.getInstance("DESEDE/CBC/PKCS5Padding");
- } catch (Exception e) {
- fail("Caught unexpected exception : " + e);
- }
-
- byte[] keyMaterial = loadBytes("hyts_" + "des-ede3-cbc.test"
- + index + ".key");
- DESedeKeySpec keySpec = new DESedeKeySpec(keyMaterial);
- SecretKeyFactory skf = SecretKeyFactory.getInstance("DESEDE");
- Key k = skf.generateSecret(keySpec);
-
- byte[] ivMaterial = loadBytes("hyts_" + "des-ede3-cbc.test"
- + index + ".iv");
- IvParameterSpec iv = new IvParameterSpec(ivMaterial);
-
- c.init(Cipher.DECRYPT_MODE, k, iv);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] input = new byte[256];
- String resPath = "hyts_" + "des-ede3-cbc.test" + index
- + ".ciphertext";
- InputStream is = Support_Resources.getStream(resPath);
-
- int bytesRead = is.read(input, 0, 256);
- while (bytesRead > 0) {
- byte[] output = c.update(input, 0, bytesRead);
- if (output != null) {
- baos.write(output);
- }
- bytesRead = is.read(input, 0, 256);
- }
-
- byte[] output = c.doFinal();
+ public void test_update$BII() throws Exception {
+ for (int index = 1; index < 4; index++) {
+ Cipher c = Cipher.getInstance("DESEDE/CBC/PKCS5Padding");
+
+ byte[] keyMaterial = loadBytes("hyts_" + "des-ede3-cbc.test"
+ + index + ".key");
+ DESedeKeySpec keySpec = new DESedeKeySpec(keyMaterial);
+ SecretKeyFactory skf = SecretKeyFactory.getInstance("DESEDE");
+ Key k = skf.generateSecret(keySpec);
+
+ byte[] ivMaterial = loadBytes("hyts_" + "des-ede3-cbc.test"
+ + index + ".iv");
+ IvParameterSpec iv = new IvParameterSpec(ivMaterial);
+
+ c.init(Cipher.DECRYPT_MODE, k, iv);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] input = new byte[256];
+ String resPath = "hyts_" + "des-ede3-cbc.test" + index
+ + ".ciphertext";
+ InputStream is = Support_Resources.getStream(resPath);
+
+ int bytesRead = is.read(input, 0, 256);
+ while (bytesRead > 0) {
+ byte[] output = c.update(input, 0, bytesRead);
if (output != null) {
baos.write(output);
}
+ bytesRead = is.read(input, 0, 256);
+ }
- byte[] decipheredCipherText = baos.toByteArray();
- is.close();
-
- byte[] plaintextBytes = loadBytes("hyts_" + "des-ede3-cbc.test"
- + index + ".plaintext");
- if (bytesArraysAreEqual(plaintextBytes, decipheredCipherText) == false) {
- fail("Operation produced incorrect results");
- }
- }// end for
- } catch (Exception e) {
- fail("Unexpected exception : " + e);
- }
+ byte[] output = c.doFinal();
+ if (output != null) {
+ baos.write(output);
+ }
+
+ byte[] decipheredCipherText = baos.toByteArray();
+ is.close();
+
+ byte[] plaintextBytes = loadBytes("hyts_" + "des-ede3-cbc.test"
+ + index + ".plaintext");
+ if (bytesArraysAreEqual(plaintextBytes, decipheredCipherText) == false) {
+ fail("Operation produced incorrect results");
+ }
+ }// end for
}
/**
* @tests javax.crypto.Cipher#doFinal()
*/
- public void test_doFinal() {
- try {
- for (int index = 1; index < 4; index++) {
- Cipher c = null;
- try {
- c = Cipher.getInstance("DESEDE/CBC/PKCS5Padding");
- } catch (Exception e) {
- fail("Caught unexpected exception : " + e);
- }
-
- byte[] keyMaterial = loadBytes("hyts_" + "des-ede3-cbc.test"
- + index + ".key");
- DESedeKeySpec keySpec = new DESedeKeySpec(keyMaterial);
- SecretKeyFactory skf = SecretKeyFactory.getInstance("DESEDE");
- Key k = skf.generateSecret(keySpec);
-
- byte[] ivMaterial = loadBytes("hyts_" + "des-ede3-cbc.test"
- + index + ".iv");
- IvParameterSpec iv = new IvParameterSpec(ivMaterial);
-
- c.init(Cipher.ENCRYPT_MODE, k, iv);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] input = new byte[256];
- String resPath = "hyts_" + "des-ede3-cbc.test" + index
- + ".plaintext";
- InputStream is = Support_Resources.getStream(resPath);
-
- int bytesRead = is.read(input, 0, 256);
- while (bytesRead > 0) {
- byte[] output = c.update(input, 0, bytesRead);
- if (output != null) {
- baos.write(output);
- }
- bytesRead = is.read(input, 0, 256);
- }
- byte[] output = c.doFinal();
+ public void test_doFinal() throws Exception {
+ for (int index = 1; index < 4; index++) {
+ Cipher c = Cipher.getInstance("DESEDE/CBC/PKCS5Padding");
+
+ byte[] keyMaterial = loadBytes("hyts_" + "des-ede3-cbc.test"
+ + index + ".key");
+ DESedeKeySpec keySpec = new DESedeKeySpec(keyMaterial);
+ SecretKeyFactory skf = SecretKeyFactory.getInstance("DESEDE");
+ Key k = skf.generateSecret(keySpec);
+
+ byte[] ivMaterial = loadBytes("hyts_" + "des-ede3-cbc.test"
+ + index + ".iv");
+ IvParameterSpec iv = new IvParameterSpec(ivMaterial);
+
+ c.init(Cipher.ENCRYPT_MODE, k, iv);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] input = new byte[256];
+ String resPath = "hyts_" + "des-ede3-cbc.test" + index
+ + ".plaintext";
+ InputStream is = Support_Resources.getStream(resPath);
+
+ int bytesRead = is.read(input, 0, 256);
+ while (bytesRead > 0) {
+ byte[] output = c.update(input, 0, bytesRead);
if (output != null) {
baos.write(output);
}
- byte[] encryptedPlaintext = baos.toByteArray();
- is.close();
-
- byte[] cipherText = loadBytes("hyts_" + "des-ede3-cbc.test"
- + index + ".cipherText");
- if (!bytesArraysAreEqual(encryptedPlaintext, cipherText)) {
- fail("Operation produced incorrect results");
- }
- }// end for
- } catch (Exception e) {
- fail("Unexpected exception : " + e);
- }
+ bytesRead = is.read(input, 0, 256);
+ }
+ byte[] output = c.doFinal();
+ if (output != null) {
+ baos.write(output);
+ }
+ byte[] encryptedPlaintext = baos.toByteArray();
+ is.close();
+
+ byte[] cipherText = loadBytes("hyts_" + "des-ede3-cbc.test"
+ + index + ".cipherText");
+ if (!bytesArraysAreEqual(encryptedPlaintext, cipherText)) {
+ fail("Operation produced incorrect results");
+ }
+ }// end for
}
private byte[] loadBytes(String resPath) {