You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/07/10 13:47:47 UTC
svn commit: r420500 - in
/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src:
main/java/javax/crypto/ test/api/java.injected/javax/crypto/
test/api/java/org/apache/harmony/crypto/tests/javax/crypto/
Author: mloenko
Date: Mon Jul 10 04:47:47 2006
New Revision: 420500
URL: http://svn.apache.org/viewvc?rev=420500&view=rev
Log:
fixes for HARMONY-758
[classlib][security]javax.crypto.spec.CipherOutputStream.write(byte[], 0, 0) throws IllegalStateException while RI does not
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Cipher.java
incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/CipherOutputStream.java
incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherOutputStreamTest.java
incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Cipher.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Cipher.java?rev=420500&r1=420499&r2=420500&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Cipher.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Cipher.java Mon Jul 10 04:47:47 2006
@@ -541,7 +541,8 @@
throw new IllegalArgumentException("The input parameter is null");
}
if (inputOffset < 0 || inputLen < 0
- || inputOffset + inputLen > input.length) {
+ || inputLen > input.length
+ || inputOffset > input.length - inputLen) {
throw new IllegalArgumentException(
"Incorrect inputOffset/inputLen parameters");
}
@@ -581,7 +582,8 @@
"Incorrect outputOffset parameter");
}
if (inputOffset < 0 || inputLen < 0
- || inputOffset + inputLen > input.length) {
+ || inputLen > input.length
+ || inputOffset > input.length - inputLen) {
throw new IllegalArgumentException(
"Incorrect inputOffset/inputLen parameters");
}
@@ -774,4 +776,4 @@
//FIXME jurisdiction policy files
return null;
}
-}
\ No newline at end of file
+}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/CipherOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/CipherOutputStream.java?rev=420500&r1=420499&r2=420500&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/CipherOutputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/CipherOutputStream.java Mon Jul 10 04:47:47 2006
@@ -72,8 +72,10 @@
* @com.intel.drl.spec_ref
*/
public void write(byte[] b, int off, int len) throws IOException {
- byte[] result;
- result = cipher.update(b, off, len);
+ if (len == 0) {
+ return;
+ }
+ byte[] result = cipher.update(b, off, len);
if (result != null) {
out.write(result);
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherOutputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherOutputStreamTest.java?rev=420500&r1=420499&r2=420500&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherOutputStreamTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/CipherOutputStreamTest.java Mon Jul 10 04:47:47 2006
@@ -21,7 +21,9 @@
package javax.crypto;
+import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
import java.util.Arrays;
import javax.crypto.NullCipher;
@@ -110,6 +112,31 @@
if (!Arrays.equals(result, data)) {
fail("CipherOutputStream wrote incorrect data.");
}
+ }
+
+ /**
+ * @tests write(byte[] b, int off, int len)
+ */
+ public void testWrite4() throws Exception {
+ //Regression for HARMONY-758
+ try {
+ new CipherOutputStream(new BufferedOutputStream((OutputStream) null), new NullCipher()).write(new byte[] {0}, 1, Integer.MAX_VALUE);
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
+ * @tests write(byte[] b, int off, int len)
+ */
+ public void testWrite5() throws Exception {
+ //Regression for HARMONY-758
+ Cipher cf = Cipher.getInstance("DES/CBC/PKCS5Padding");
+ NullCipher nc = new NullCipher();
+ CipherOutputStream stream1 = new CipherOutputStream(new BufferedOutputStream((OutputStream) null), nc);
+ CipherOutputStream stream2 = new CipherOutputStream(stream1, cf);
+ CipherOutputStream stream3 = new CipherOutputStream(stream2, nc);
+ stream3.write(new byte[] {0}, 0, 0);
+ //no exception expected
}
/**
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java?rev=420500&r1=420499&r2=420500&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java Mon Jul 10 04:47:47 2006
@@ -182,6 +182,18 @@
}
/*
+ * Class under test for byte[] update(byte[], int, int)
+ */
+ public void testUpdatebyteArrayintint2() {
+ //Regression for HARMONY-758
+ try {
+ new NullCipher().update(new byte[1], 1, Integer.MAX_VALUE);
+ fail("Expected IllegalArgumentException was not thrown");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /*
* Class under test for int doFinal(byte[], int, int, byte[])
*/
public void testDoFinalbyteArrayintintbyteArray() throws Exception {
@@ -192,6 +204,31 @@
}
/*
+ * Class under test for int doFinal(byte[], int, int, byte[])
+ */
+ public void testDoFinalbyteArrayintintbyteArray2() throws Exception {
+ //Regression for HARMONY-758
+ try {
+ new NullCipher().update(new byte[1], 1, Integer.MAX_VALUE,
+ new byte[1]);
+ fail("Expected IllegalArgumentException was not thrown");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /*
+ * Class under test for int doFinal(byte[], int, int, byte[])
+ */
+ public void testDoFinalbyteArrayintintbyteArray3() throws Exception {
+ //Regression for HARMONY-758
+ try {
+ new NullCipher().update(new byte[1], 0, 1, new byte[0]);
+ fail("Expected ArrayIndexOutOfBoundsException was not thrown");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ }
+
+ /*
* Class under test for int doFinal(byte[], int, int, byte[], int)
*/
public void testDoFinalbyteArrayintintbyteArrayint() throws Exception {
@@ -199,5 +236,31 @@
byte [] r = new byte[5];
c.doFinal(b, 0, 5, r, 0);
assertTrue("different content", Arrays.equals(b, r));
+ }
+
+ /*
+ * Class under test for int doFinal(byte[], int, int, byte[], int)
+ */
+ public void testDoFinalbyteArrayintintbyteArrayint2() throws Exception {
+ //Regression for HARMONY-758
+ try {
+ new NullCipher().update(new byte[1], 1, Integer.MAX_VALUE,
+ new byte[1], 0);
+ fail("Expected IllegalArgumentException was not thrown");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /*
+ * Class under test for int doFinal(byte[], int, int, byte[], int)
+ */
+ public void testDoFinalbyteArrayintintbyteArrayint3() throws Exception {
+ //Regression for HARMONY-758
+ try {
+ new NullCipher().update(new byte[1], 0, 1,
+ new byte[0], 0);
+ fail("Expected ArrayIndexOutOfBoundsException was not thrown");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
}
}