1 package org.bouncycastle.asn1;
2
3 import java.io.*;
4 import java.util.*;
5
6 public class DERSequence
7 extends ASN1Sequence
8 {
9 /**
10 * create an empty sequence
11 */
12 public DERSequence()
13 {
14 }
15
16 /**
17 * create a sequence containing one object
18 */
19 public DERSequence(
20 DEREncodable obj)
21 {
22 this.addObject(obj);
23 }
24
25 /**
26 * create a sequence containing a vector of objects.
27 */
28 public DERSequence(
29 DEREncodableVector v)
30 {
31 for (int i = 0; i != v.size(); i++)
32 {
33 this.addObject(v.get(i));
34 }
35 }
36
37 /*
38 * A note on the implementation:
39 * <p>
40 * As DER requires the constructed, definite-length model to
41 * be used for structured types, this varies slightly from the
42 * ASN.1 descriptions given. Rather than just outputing SEQUENCE,
43 * we also have to specify CONSTRUCTED, and the objects length.
44 */
45 void encode(
46 DEROutputStream out)
47 throws IOException
48 {
49 ByteArrayOutputStream bOut = new ByteArrayOutputStream();
50 DEROutputStream dOut = new DEROutputStream(bOut);
51 Enumeration e = this.getObjects();
52
53 while (e.hasMoreElements())
54 {
55 Object obj = e.nextElement();
56
57 dOut.writeObject(obj);
58 }
59
60 dOut.close();
61
62 byte[] bytes = bOut.toByteArray();
63
64 out.writeEncoded(SEQUENCE | CONSTRUCTED, bytes);
65 }
66 }
67