harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r502260 - 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 16:14:40 GMT
Author: smishura
Date: Thu Feb  1 08:14:39 2007
New Revision: 502260

URL: http://svn.apache.org/viewvc?view=rev&rev=502260
Log:
Apply modified patch for HARMONY-1148:
[classlib][security] compatibility: method MessageDigest.digest(..) throws different exception
on RI and Harmony

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=502260&r1=502259&r2=502260
==============================================================================
--- 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 08:14:39 2007
@@ -203,9 +203,13 @@
      *  
      */
     public int digest(byte[] buf, int offset, int len) throws DigestException {
-        if (buf == null || offset < 0 || len < 0 ||
-                (long)offset + (long)len > buf.length) {
-            throw new IllegalArgumentException(Messages.getString("security.05")); //$NON-NLS-1$
+        if (buf == null ||
+                // offset < 0 || len < 0 ||
+                // checks for negative values are commented out intentionally
+                // see HARMONY-1148 for details
+                (long) offset + (long) len > buf.length) {
+            throw new IllegalArgumentException(Messages
+                    .getString("security.05")); //$NON-NLS-1$
         }
         return engineDigest(buf, 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=502260&r1=502259&r2=502260
==============================================================================
--- 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 08:14:39 2007
@@ -130,6 +130,48 @@
 		}
 	}
 
+    /**
+     * @tests java.security.MessageDigest#digest(byte[], int, int)
+     */
+    public void test_digestLB$LILI() throws Exception {
+
+        // Regression for Harmony-1148
+        MessageDigest md = new MyMessageDigest1();
+        final byte[] bytes = new byte[] { 2, 4, 1 };
+        try {
+            // buf == null
+            md.digest(null, 0, 1);
+            fail("No expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            // offset + len > buf.length
+            md.digest(bytes, 0, bytes.length + 1);
+            fail("No expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            // offset + len > Integer.MAX_VALUE
+            md.digest(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;
+        final int status = 33;
+        md = new MyMessageDigest1("ABC") {
+            @Override
+            public int engineDigest(byte[] arg0, int arg1, int arg2) {
+                assertSame("buf", bytes, arg0);
+                assertEquals("offset", offset, arg1);
+                assertEquals("len", len, arg2);
+                return status;
+            }
+        };
+        assertEquals("returned status", status, md.digest(bytes, offset, len));
+    }
+
 	public void testIsEqual() {
 		byte[] b1 = {1, 2, 3, 4};
 		byte[] b2 = {1, 2, 3, 4, 5};
@@ -181,6 +223,22 @@
         }
         // No exception for len < 0
         md.update(bytes, 1, -1);
+        
+        //Regression for Harmony-1148
+        md = MessageDigest.getInstance("SHA");
+        try {
+            // offset < 0
+            md.digest(bytes, 0, -1);
+            fail("No expected DigestException");
+        } catch (DigestException e) {
+        }
+        try {
+            // len < 0
+            md.digest(bytes, -1, 0);
+            fail("No expected DigestException");
+        } catch (DigestException e) {
+        }
+
     }
 }
 



Mime
View raw message