1package org.bouncycastle.asn1;
2
3import java.io.IOException;
4import java.util.Enumeration;
5
6public class BERSequence
7    extends ASN1Sequence
8{
9    /**
10     * create an empty sequence
11     */
12    public BERSequence()
13    {
14    }
15
16    /**
17     * create a sequence containing one object
18     */
19    public BERSequence(
20        ASN1Encodable obj)
21    {
22        super(obj);
23    }
24
25    /**
26     * create a sequence containing a vector of objects.
27     */
28    public BERSequence(
29        ASN1EncodableVector v)
30    {
31        super(v);
32    }
33
34    /**
35     * create a sequence containing an array of objects.
36     */
37    public BERSequence(
38        ASN1Encodable[]   array)
39    {
40        super(array);
41    }
42
43    int encodedLength()
44        throws IOException
45    {
46        int length = 0;
47        for (Enumeration e = getObjects(); e.hasMoreElements();)
48        {
49            length += ((ASN1Encodable)e.nextElement()).toASN1Primitive().encodedLength();
50        }
51
52        return 2 + length + 2;
53    }
54
55    /*
56     */
57    void encode(
58        ASN1OutputStream out)
59        throws IOException
60    {
61        out.write(BERTags.SEQUENCE | BERTags.CONSTRUCTED);
62        out.write(0x80);
63
64        Enumeration e = getObjects();
65        while (e.hasMoreElements())
66        {
67            out.writeObject((ASN1Encodable)e.nextElement());
68        }
69
70        out.write(0x00);
71        out.write(0x00);
72    }
73}
74