1
package org.bouncycastle.asn1;
3
import java.io.ByteArrayOutputStream;
4
import java.io.IOException;
5
import java.util.Enumeration;
8
* A DER encoded set object
21
* @param obj - a single object that makes up the set.
30
* @param v - a vector of objects making up the set.
33
ASN1EncodableVector v)
39
* create a set from an array of objects.
44
for (int i = 0; i != a.length; i++)
53
* @param v - a vector of objects making up the set.
56
ASN1EncodableVector v,
59
for (int i = 0; i != v.size(); i++)
61
this.addObject(v.get(i));
71
* A note on the implementation:
73
* As DER requires the constructed, definite-length model to
74
* be used for structured types, this varies slightly from the
75
* ASN.1 descriptions given. Rather than just outputing SET,
76
* we also have to specify CONSTRUCTED, and the objects length.
82
// TODO Intermediate buffer could be avoided if we could calculate expected length
83
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
84
DEROutputStream dOut = new DEROutputStream(bOut);
85
Enumeration e = this.getObjects();
87
while (e.hasMoreElements())
89
Object obj = e.nextElement();
91
dOut.writeObject(obj);
96
byte[] bytes = bOut.toByteArray();
98
out.writeEncoded(SET | CONSTRUCTED, bytes);