1package org.bouncycastle.asn1;
2
3import java.io.IOException;
4import java.util.Enumeration;
5
6public class BERSet
7    extends DERSet
8{
9    /**
10     * create an empty sequence
11     */
12    public BERSet()
13    {
14    }
15
16    /**
17     * create a set containing one object
18     */
19    public BERSet(
20        DEREncodable    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     * @param v - a vector of objects making up the set.
36     */
37    BERSet(
38        ASN1EncodableVector  v,
39        boolean              needsSorting)
40    {
41        super(v, needsSorting);
42    }
43
44    /*
45     */
46    void encode(
47        DEROutputStream out)
48        throws IOException
49    {
50        if (out instanceof ASN1OutputStream || out instanceof BEROutputStream)
51        {
52            out.write(SET | CONSTRUCTED);
53            out.write(0x80);
54
55            Enumeration e = getObjects();
56            while (e.hasMoreElements())
57            {
58                out.writeObject(e.nextElement());
59            }
60
61            out.write(0x00);
62            out.write(0x00);
63        }
64        else
65        {
66            super.encode(out);
67        }
68    }
69}
70