KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > bc > asn1 > DERConstructedSet


1 package com.lowagie.bc.asn1;
2
3 import java.io.ByteArrayOutputStream;
4 import java.io.IOException;
5 import java.util.Enumeration;
6
7 public class DERConstructedSet
8     extends ASN1Set
9 {
10     public DERConstructedSet()
11     {
12     }
13
14     /**
15      * @param obj - a single object that makes up the set.
16      */

17     public DERConstructedSet(
18         DEREncodable obj)
19     {
20         this.addObject(obj);
21     }
22
23     /**
24      * @param v - a vector of objects making up the set.
25      */

26     public DERConstructedSet(
27         DEREncodableVector v)
28     {
29         for (int i = 0; i != v.size(); i++)
30         {
31             this.addObject(v.get(i));
32         }
33     }
34
35     public void addObject(
36         DEREncodable obj)
37     {
38         super.addObject(obj);
39     }
40
41     public int getSize()
42     {
43         return size();
44     }
45
46     /*
47      * A note on the implementation:
48      * <p>
49      * As DER requires the constructed, definite-length model to
50      * be used for structured types, this varies slightly from the
51      * ASN.1 descriptions given. Rather than just outputing SET,
52      * we also have to specify CONSTRUCTED, and the objects length.
53      */

54     void encode(
55         DEROutputStream out)
56         throws IOException
57     {
58         ByteArrayOutputStream bOut = new ByteArrayOutputStream();
59         DEROutputStream dOut = new DEROutputStream(bOut);
60         Enumeration e = this.getObjects();
61
62         while (e.hasMoreElements())
63         {
64             Object obj = e.nextElement();
65
66             dOut.writeObject(obj);
67         }
68
69         dOut.close();
70
71         byte[] bytes = bOut.toByteArray();
72
73         out.writeEncoded(SET | CONSTRUCTED, bytes);
74     }
75 }
76
Popular Tags