This fixes some of the problems with our `EncryptedPrivateKeyInfo' class. We still need to flesh out a more complete mapping between algorithm names and OIDs.

2006-02-01  Casey Marshall  <[EMAIL PROTECTED]>

        Partial fix for PR classpath/25143.
        * javax/crypto/EncryptedPrivateKeyInfo.java (algName): new field.
        (<init>): fill in `algName,' derive `algOid' from `algName.'
        (getOid): new method.
        (encode): embed NULL value for parameters if `params' is `null.'

Committed,

Index: javax/crypto/EncryptedPrivateKeyInfo.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/crypto/EncryptedPrivateKeyInfo.java,v
retrieving revision 1.3
diff -u -B -b -r1.3 EncryptedPrivateKeyInfo.java
--- javax/crypto/EncryptedPrivateKeyInfo.java   2 Jul 2005 20:32:45 -0000       
1.3
+++ javax/crypto/EncryptedPrivateKeyInfo.java   2 Feb 2006 07:14:31 -0000
@@ -92,6 +92,9 @@
   /** The OID of the encryption algorithm. */
   private OID algOid;
 
+  /** The encryption algorithm name. */
+  private String algName;
+
   /** The encryption algorithm's parameters. */
   private AlgorithmParameters params;
 
@@ -125,7 +128,8 @@
         throw new IllegalArgumentException("0-length encryptedData");
       }
     this.params = params;
-    algOid = new OID(params.getAlgorithm());
+    algName = params.getAlgorithm ();
+    algOid = getOid (algName);
     this.encryptedData = (byte[]) encryptedData.clone();
   }
 
@@ -168,10 +172,36 @@
       {
         throw new IllegalArgumentException("0-length encryptedData");
       }
-    this.algOid = new OID(algName);
+    this.algName = algName.toString (); // do NP check
+    this.algOid = getOid (algName);
     this.encryptedData = (byte[]) encryptedData.clone();
   }
 
+  /**
+   * Return the OID for the given cipher name.
+   *
+   * @param str The string.
+   * @throws NoSuchAlgorithmException If the OID is not known.
+   */
+  private static OID getOid (final String str)
+    throws NoSuchAlgorithmException
+  {
+    if (str.equalsIgnoreCase ("DSA"))
+      {
+        return new OID ("1.2.840.10040.4.3");
+      }
+    // FIXME add more
+
+    try
+      {
+        return new OID (str);
+      }
+    catch (Throwable t)
+      {
+      }
+    throw new NoSuchAlgorithmException ("cannot determine OID for '" + str + 
"'");
+  }
+
   // Instance methods.
   // ------------------------------------------------------------------------
 
@@ -196,6 +226,7 @@
           }
         catch (NoSuchAlgorithmException ignore)
           {
+            // FIXME throw exception?
           }
         catch (IOException ignore)
           {
@@ -272,7 +303,11 @@
     getAlgParameters();
     if (params != null)
       {
-        algId.add(DERReader.read(params.getEncoded()));
+        algId.add (DERReader.read (params.getEncoded()));
+      }
+    else
+      {
+        algId.add (new DERValue (DER.NULL, null));
       }
     List epki = new ArrayList(2);
     epki.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, algId));

Reply via email to