harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r502251 - in /harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/java/security/MessageDigest.java test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java
Date Thu, 01 Feb 2007 15:52:59 GMT
Author: smishura
Date: Thu Feb  1 07:52:58 2007
New Revision: 502251

URL: http://svn.apache.org/viewvc?view=rev&rev=502251
Log:
Apply modified patch for HARMONY-1120:
[class][security] MessageDigest.update(byte[], int, int) incompatible with RI exceptions

Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/MessageDigest.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/MessageDigest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/MessageDigest.java?view=diff&rev=502251&r1=502250&r2=502251
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/MessageDigest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/MessageDigest.java
Thu Feb  1 07:52:58 2007
@@ -164,9 +164,13 @@
      *  
      */
     public void update(byte[] input, int offset, int len) {
-        if (input == null || offset < 0 || len < 0 ||
-                (long)offset + (long)len > input.length) {
-            throw new IllegalArgumentException(Messages.getString("security.05")); //$NON-NLS-1$
+        if (input == null ||
+                // offset < 0 || len < 0 ||
+                // checks for negative values are commented out intentionally
+                // see HARMONY-1120 for details
+                (long) offset + (long) len > input.length) {
+            throw new IllegalArgumentException(Messages
+                    .getString("security.05")); //$NON-NLS-1$
         }
         engineUpdate(input, offset, len);
     }

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java?view=diff&rev=502251&r1=502250&r2=502251
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java
Thu Feb  1 07:52:58 2007
@@ -51,17 +51,49 @@
 		}
 	}
 
-	/*
-	 * Class under test for void update(byte[], int, int)
-	 */
-	public void testUpdatebyteArrayintint() {
-		MyMessageDigest1 md = new MyMessageDigest1("ABC");
-		byte[] b = {1, 2, 3, 4, 5};
-		md.update(b, 1, 2);
-		if (!md.runEngineUpdate2) {
-			fail("update failed");
-		}
-	}
+	/**
+     * @tests java.security.MessageDigest#update(byte[], int, int)
+     */
+    public void test_updateLB$LILI() {
+        MyMessageDigest1 md = new MyMessageDigest1("ABC");
+        final byte[] bytes = { 1, 2, 3, 4, 5 };
+        md.update(bytes, 1, 2);
+        assertTrue(md.runEngineUpdate2);
+
+        // Regression for HARMONY-1120
+        try {
+            // buf == null
+            md.update(null, 0, 1);
+            fail("No expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            // offset + len > buf.length
+            md.update(bytes, 0, bytes.length + 1);
+            fail("No expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            // offset + len > Integer.MAX_VALUE
+            md.update(bytes, Integer.MAX_VALUE, 1);
+            fail("No expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        // offset<0 and len<0 are passed to provider
+        final int offset = -1;
+        final int len = -1;
+        md = new MyMessageDigest1("ABC") {
+            @Override
+            public void engineUpdate(byte[] arg0, int arg1, int arg2) {
+                assertSame("buf", bytes, arg0);
+                assertEquals("offset", offset, arg1);
+                assertEquals("len", len, arg2);
+                runEngineUpdate2 = true;
+            }
+        };
+        md.update(bytes, offset, len);
+        assertTrue(md.runEngineUpdate2);
+    }
 
 	/*
 	 * Class under test for void update(byte[])
@@ -131,5 +163,24 @@
 			fail("getDigestLength failed");
 		}
 	}
+    
+    /**
+     * Tests SHA MessageDigest provider
+     */
+    public void testSHAProvider() throws Exception {
+        MessageDigest md = MessageDigest.getInstance("SHA");
+        byte[] bytes = new byte[] { 1, 1, 1, 1, 1 };
+
+        // Regression for HARMONY-1120
+        // testing combination with provider
+        try {
+            // offset < 0
+            md.update(bytes, -1, 1);
+            fail("No expected IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+        }
+        // No exception for len < 0
+        md.update(bytes, 1, -1);
+    }
 }
 



Mime
View raw message