resolve darcs stupidity
[org.ibex.core.git] / src / org / bouncycastle / asn1 / BERTaggedObject.java
index b24f037..f01d199 100644 (file)
@@ -12,86 +12,96 @@ public class BERTaggedObject
     extends DERTaggedObject
 {
     /**
-     * This creates an empty tagged object of tagNo (ie. zero length).
-     *
      * @param tagNo the tag number for this object.
+     * @param obj the tagged object.
      */
     public BERTaggedObject(
-        int     tagNo)
+        int             tagNo,
+        DEREncodable    obj)
     {
-               super(tagNo);
+                super(tagNo, obj);
     }
 
     /**
+     * @param explicit true if an explicitly tagged object.
      * @param tagNo the tag number for this object.
      * @param obj the tagged object.
      */
     public BERTaggedObject(
-        int         tagNo,
-        DERObject   obj)
+        boolean         explicit,
+        int             tagNo,
+        DEREncodable    obj)
     {
-               super(tagNo, obj);
+                super(explicit, tagNo, obj);
     }
 
     /**
-     * @param explicit true if an explicitly tagged object.
-     * @param tagNo the tag number for this object.
-     * @param obj the tagged object.
+     * create an implicitly tagged object that contains a zero
+     * length sequence.
      */
     public BERTaggedObject(
-        boolean     explicit,
-        int         tagNo,
-        DERObject   obj)
+        int             tagNo)
     {
-               super(explicit, tagNo, obj);
+        super(false, tagNo, new BERConstructedSequence());
     }
 
     void encode(
         DEROutputStream  out)
         throws IOException
     {
-               if (out instanceof BEROutputStream)
-               {
+        if (out instanceof ASN1OutputStream || out instanceof BEROutputStream)
+        {
             out.write(CONSTRUCTED | TAGGED | tagNo);
             out.write(0x80);
 
-                       if (!empty)
-                       {
-                               ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
-                               BEROutputStream         dOut = new BEROutputStream(bOut);
-
+            if (!empty)
+            {
                 if (!explicit)
                 {
                     if (obj instanceof BERConstructedOctetString)
                     {
-                        Vector  octs = ((BERConstructedOctetString)obj).getDEROctets();
+                        Enumeration  e = ((BERConstructedOctetString)obj).getObjects();
+
+                        while (e.hasMoreElements())
+                        {
+                            out.writeObject(e.nextElement());
+                        }
+                    }
+                    else if (obj instanceof ASN1Sequence)
+                    {
+                        Enumeration  e = ((ASN1Sequence)obj).getObjects();
 
-                        for (int i = 0; i != octs.size(); i++)
+                        while (e.hasMoreElements())
                         {
-                            dOut.writeObject(octs.elementAt(i));
+                            out.writeObject(e.nextElement());
+                        }
+                    }
+                    else if (obj instanceof ASN1Set)
+                    {
+                        Enumeration  e = ((ASN1Set)obj).getObjects();
+
+                        while (e.hasMoreElements())
+                        {
+                            out.writeObject(e.nextElement());
                         }
                     }
                     else
                     {
-                        dOut.writeObject(obj); // hmmm...
+                        throw new RuntimeException("not implemented: " + obj.getClass().getName());
                     }
                 }
                 else
                 {
-                                   dOut.writeObject(obj);
+                    out.writeObject(obj);
                 }
-
-                               dOut.close();
-
-                out.write(bOut.toByteArray());
-                       }
+            }
 
             out.write(0x00);
             out.write(0x00);
-               }
-               else
-               {
-                       super.encode(out);
-               }
+        }
+        else
+        {
+            super.encode(out);
+        }
     }
 }