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