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/11 06:15:44 UTC

svn commit: r420706 - in /incubator/harmony/enhanced/classlib/trunk/modules/crypto/src: main/java/javax/crypto/EncryptedPrivateKeyInfo.java test/api/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java

Author: mloenko
Date: Mon Jul 10 21:15:43 2006
New Revision: 420706

URL: http://svn.apache.org/viewvc?rev=420706&view=rev
Log:
fixes for HARMONY-768
[classlib][security] compatibility: exception order for javax.crypto.EncryptedPrivateKeyInfo(String algName, byte[] encryptedData )

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/EncryptedPrivateKeyInfo.java
    incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/EncryptedPrivateKeyInfo.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/EncryptedPrivateKeyInfo.java?rev=420706&r1=420705&r2=420706&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/EncryptedPrivateKeyInfo.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/EncryptedPrivateKeyInfo.java Mon Jul 10 21:15:43 2006
@@ -110,6 +110,9 @@
             throw new NullPointerException("the algName parameter is null");
         }
         this.algName = encrAlgName;
+        if (!mapAlgName()) {
+            throw new NoSuchAlgorithmException(this.algName + " not supported");
+        }
         if (encryptedData == null) {
             throw new NullPointerException(
                     "the encryptedData parameter is null");
@@ -121,9 +124,6 @@
         System.arraycopy(encryptedData, 0,
                 this.encryptedData, 0, encryptedData.length);
         this.algParameters = null;
-        if (!mapAlgName()) {
-            throw new NoSuchAlgorithmException(this.algName + " not supported");
-        }
     }
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.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/EncryptedPrivateKeyInfoTest.java?rev=420706&r1=420705&r2=420706&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java Mon Jul 10 21:15:43 2006
@@ -59,11 +59,7 @@
  */
 public class EncryptedPrivateKeyInfoTest extends TestCase {
 
-    private static final Provider[] provider;
-    
-    static {
-        provider = Security.getProviders();
-    }
+    private static final Provider[] provider = Security.getProviders();
 
     /**
      * Algorithm names/transformations used in roundtrip tests of
@@ -484,6 +480,20 @@
     }
 
     /**
+     * @tests javax/crypto/EncryptedPrivateKeyInfo(String, byte[])
+     * Checks exception order
+     */
+    public final void testEncryptedPrivateKeyInfoStringbyteArray6() {
+        //Regression for HARMONY-768
+        try {
+            new EncryptedPrivateKeyInfo("0", new byte[] {});
+            fail("NoSuchAlgorithmException expected");
+        } catch (NoSuchAlgorithmException e) {
+            //expected
+        }    
+    }
+
+    /**
      * Test #1 for
      * <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[])
      * </code>
@@ -1586,31 +1596,14 @@
             ap = c.getParameters();
 
             try {
-                //                int blkS = c.getBlockSize();
-                //                blkS = blkS==0?10:blkS;
-                //                ct = new byte[c.getOutputSize(privateKeyInfo.length)];
-                //                if (blkS != 0) {
-                //                    int cltOff = 0, ctOff = 0;
-                //                    for (int i=0; i<privateKeyInfo.length/blkS; i++) {
-                //                        ctOff += c.update(privateKeyInfo, cltOff, blkS, ct, ctOff);
-                //                        cltOff += blkS;
-                //                    }
-                //                    c.doFinal(privateKeyInfo, cltOff, privateKeyInfo.length%blkS,
-                // ct, ctOff);
-                //                } else {
                 ct = c.doFinal(privateKeyInfo);
-                //                }
             } catch (IllegalStateException e) {
                 throw new AllowedFailure(e.getMessage());
             } catch (IllegalBlockSizeException e) {
                 throw new AllowedFailure(e.getMessage());
             } catch (BadPaddingException e) {
                 throw new AllowedFailure(e.getMessage());
-            }
-            //            } catch (ShortBufferException e) {
-            //                throw new AllowedFailure(e.getMessage());
-            //            }
-            catch (RuntimeException e) {
+            } catch (RuntimeException e) {
                 throw new AllowedFailure(e.getMessage());
             }
 
@@ -1930,4 +1923,4 @@
             (byte) 0x9f, (byte) 0x3e, (byte) 0xf5, (byte) 0x19, (byte) 0xa3, // 150
             (byte) 0xae, (byte) 0x64, (byte) 0x69, (byte) 0x14, (byte) 0x07,
             (byte) 0x50, (byte) 0x97, };
-}
\ No newline at end of file
+}