f1dba330dad4c926217bf142535b342948831e2e
[org.ibex.core.git] / src / org / bouncycastle / asn1 / DERConstructedSequence.java
1 package org.bouncycastle.asn1;
2
3 import java.io.*;
4 import java.util.*;
5
6 public class DERConstructedSequence
7     extends ASN1Sequence
8 {
9     public void addObject(
10         DEREncodable obj)
11     {
12         super.addObject(obj);
13     }
14
15     public int getSize()
16     {
17         return size();
18     }
19
20     /*
21      * A note on the implementation:
22      * <p>
23      * As DER requires the constructed, definite-length model to
24      * be used for structured types, this varies slightly from the
25      * ASN.1 descriptions given. Rather than just outputing SEQUENCE,
26      * we also have to specify CONSTRUCTED, and the objects length.
27      */
28     void encode(
29         DEROutputStream out)
30         throws IOException
31     {
32         ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
33         DEROutputStream         dOut = new DEROutputStream(bOut);
34         Enumeration             e = this.getObjects();
35
36         while (e.hasMoreElements())
37         {
38             Object    obj = e.nextElement();
39
40             dOut.writeObject(obj);
41         }
42
43         dOut.close();
44
45         byte[]  bytes = bOut.toByteArray();
46
47         out.writeEncoded(SEQUENCE | CONSTRUCTED, bytes);
48     }
49 }