This fix is part of what is needed to fix bug 25144. Someone else suggested the `toString' change below, but I forget who and searching the archive produced nothing. If you remember (or are the person) please remind me so we can credit him (you) properly.

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

        toString fix suggested by ???.
        * gnu/java/security/der/DERValue.java
        (getLength, getEncoded, getEncodedLength): throw an exception,
        don't initialize `encoded' to a bogus value.
        (toString): return a more helpful string.

        Partial fix for PR classpath/25144.
        * gnu/java/security/der/DERWriter.java (write): if the value is
        the pseudo-value used for CONSTRUCTED, write the encoded value
        directly.

Committed,

Index: gnu/java/security/der/DERValue.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/security/der/DERValue.java,v
retrieving revision 1.4
diff -u -B -b -r1.4 DERValue.java
--- gnu/java/security/der/DERValue.java 2 Jul 2005 20:32:14 -0000       1.4
+++ gnu/java/security/der/DERValue.java 2 Feb 2006 07:00:37 -0000
@@ -38,6 +38,8 @@
 
 package gnu.java.security.der;
 
+import gnu.java.security.x509.Util;
+
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
@@ -108,7 +110,9 @@
           }
         catch (IOException ioe)
           {
-            encoded = new byte[0];
+            IllegalArgumentException iae = new IllegalArgumentException ();
+            iae.initCause (ioe);
+            throw iae;
           }
       }
     return length;
@@ -138,7 +142,9 @@
           }
         catch (IOException ioe)
           {
-            encoded = new byte[0];
+            IllegalArgumentException iae = new IllegalArgumentException ();
+            iae.initCause (ioe);
+            throw iae;
           }
       }
     return (byte[]) encoded.clone();
@@ -156,7 +162,9 @@
           }
         catch (IOException ioe)
           {
-            encoded = new byte[0];
+            IllegalArgumentException iae = new IllegalArgumentException ();
+            iae.initCause (ioe);
+            throw iae;
           }
       }
     return encoded.length;
@@ -164,7 +172,18 @@
 
   public String toString()
   {
-    return "DERValue [ tag=" + tag + ", class=" + tagClass + ", constructed="
-      + constructed + ", value=" + value + " ]";
+    String start = "DERValue ( [";
+    if (tagClass == DER.UNIVERSAL) 
+      start = start + "UNIVERSAL ";
+    else if (tagClass == DER.PRIVATE) 
+      start = start + "PRIVATE ";
+    else if (tagClass == DER.APPLICATION) 
+      start = start + "APPLICATION ";
+    start = start + tag + "] constructed=" + constructed + ", value=";
+    if (constructed)
+     start = start + "\n" + Util.hexDump(getEncoded(), "\t");
+    else
+     start = start + value;
+    return start + " )";
   }
 }
Index: gnu/java/security/der/DERWriter.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/security/der/DERWriter.java,v
retrieving revision 1.5
diff -u -B -b -r1.5 DERWriter.java
--- gnu/java/security/der/DERWriter.java        2 Jul 2005 20:32:14 -0000       
1.5
+++ gnu/java/security/der/DERWriter.java        2 Feb 2006 07:00:37 -0000
@@ -84,6 +84,12 @@
   public static int write(OutputStream out, DERValue object)
     throws IOException
   {
+    if (DER.CONSTRUCTED_VALUE.equals (object.getValue ()))
+      {
+        out.write (object.getEncoded ());
+        return object.getLength ();
+      }
+
     out.write(object.getExternalTag());
     Object value = object.getValue();
     if (value == null)

Reply via email to