harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r526042 - in /harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/java/security/SecureRandom.java test/api/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java
Date Fri, 06 Apr 2007 03:43:22 GMT
Author: pyang
Date: Thu Apr  5 20:43:22 2007
New Revision: 526042

URL: http://svn.apache.org/viewvc?view=rev&rev=526042
Log:
Apply patch for HARMONY-3552([classlib][security]java.security.SecureRandom.next(int bitCount)
returns a int which has a longer bit length than required.)

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

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/SecureRandom.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/SecureRandom.java?view=diff&rev=526042&r1=526041&r2=526042
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/SecureRandom.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/SecureRandom.java
Thu Apr  5 20:43:22 2007
@@ -301,7 +301,7 @@
         for (int i = 0; i < bytes; i++) {
             ret = (next[i] & 0xFF) | (ret << 8);
         }    
-        ret = ret >> (bytes*8 - numBits);
+        ret = ret >>> (bytes*8 - numBits);
         return ret;
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java?view=diff&rev=526042&r1=526041&r2=526042
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java
Thu Apr  5 20:43:22 2007
@@ -172,4 +172,58 @@
         
         assertEquals("unknown", sr.getAlgorithm());
     }
+    
+    //Regression Test for HARMONY-3552.
+    public void test_nextJ() throws Exception {
+        MySecureRandom mySecureRandom = new MySecureRandom(
+                new MySecureRandomSpi(), null);
+        int numBits = 29;
+        int random = mySecureRandom.getNext(numBits);
+        assertEquals(numBits, Integer.bitCount(random));
+        
+        numBits = 0;
+        random = mySecureRandom.getNext(numBits);
+        assertEquals(numBits, Integer.bitCount(random));
+        
+        numBits = 40;
+        random = mySecureRandom.getNext(numBits);
+        assertEquals(32, Integer.bitCount(random));     
+        
+        numBits = -1;
+        random = mySecureRandom.getNext(numBits);
+        assertEquals(0, Integer.bitCount(random));
+    }
+    
+    class MySecureRandom extends SecureRandom {
+        private static final long serialVersionUID = 1L;
+
+        public MySecureRandom(SecureRandomSpi secureRandomSpi, Provider provider) {
+            super(secureRandomSpi, provider);
+        }
+
+        public int getNext(int numBits) {
+            return super.next(numBits);
+        }
+    }
+
+    class MySecureRandomSpi extends SecureRandomSpi {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected byte[] engineGenerateSeed(int arg0) {
+            return null;
+        }
+
+        @Override
+        protected void engineNextBytes(byte[] bytes) {
+            for (int i = 0; i < bytes.length; i++) {
+                bytes[i] = (byte) 0xFF;
+            }
+        }
+
+        @Override
+        protected void engineSetSeed(byte[] arg0) {
+            return;
+        }
+    }
 }



Mime
View raw message