01: package org.bouncycastle.asn1;
02:
03: import java.io.ByteArrayOutputStream;
04: import java.io.IOException;
05: import java.util.Enumeration;
06:
07: /**
08: *
09: * @deprecated use DERSet
10: */
11: public class DERConstructedSet extends ASN1Set {
12: public DERConstructedSet() {
13: }
14:
15: /**
16: * @param obj - a single object that makes up the set.
17: */
18: public DERConstructedSet(DEREncodable obj) {
19: this .addObject(obj);
20: }
21:
22: /**
23: * @param v - a vector of objects making up the set.
24: */
25: public DERConstructedSet(DEREncodableVector v) {
26: for (int i = 0; i != v.size(); i++) {
27: this .addObject(v.get(i));
28: }
29: }
30:
31: public void addObject(DEREncodable obj) {
32: super .addObject(obj);
33: }
34:
35: public int getSize() {
36: return size();
37: }
38:
39: /*
40: * A note on the implementation:
41: * <p>
42: * As DER requires the constructed, definite-length model to
43: * be used for structured types, this varies slightly from the
44: * ASN.1 descriptions given. Rather than just outputing SET,
45: * we also have to specify CONSTRUCTED, and the objects length.
46: */
47: void encode(DEROutputStream out) throws IOException {
48: ByteArrayOutputStream bOut = new ByteArrayOutputStream();
49: DEROutputStream dOut = new DEROutputStream(bOut);
50: Enumeration e = this .getObjects();
51:
52: while (e.hasMoreElements()) {
53: Object obj = e.nextElement();
54:
55: dOut.writeObject(obj);
56: }
57:
58: dOut.close();
59:
60: byte[] bytes = bOut.toByteArray();
61:
62: out.writeEncoded(SET | CONSTRUCTED, bytes);
63: }
64: }
|