1package org.bouncycastle.asn1;
2
3import java.io.IOException;
4import java.util.Enumeration;
5
6public class BERSet
7    extends ASN1Set
8{
9    /**
10     * create an empty sequence
11     */
12    public BERSet()
13    {
14    }
15
16    /**
17     * @param obj - a single object that makes up the set.
18     */
19    public BERSet(
20        ASN1Encodable obj)
21    {
22        super(obj);
23    }
24
25    /**
26     * @param v - a vector of objects making up the set.
27     */
28    public BERSet(
29        ASN1EncodableVector v)
30    {
31        super(v, false);
32    }
33
34    /**
35     * create a set from an array of objects.
36     */
37    public BERSet(
38        ASN1Encodable[]   a)
39    {
40        super(a, false);
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.SET | 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