1 package org.bouncycastle.asn1; 2 3 import java.io.IOException; 4 import java.util.Enumeration; 5 6 /** 7 * Carrier class for an indefinite-length SET. 8 */ 9 public class BERSet 10 extends ASN1Set 11 { 12 /** 13 * Create an empty SET. 14 */ 15 public BERSet() 16 { 17 } 18 19 /** 20 * Create a SET containing one object. 21 * 22 * @param obj - a single object that makes up the set. 23 */ 24 public BERSet( 25 ASN1Encodable obj) 26 { 27 super(obj); 28 } 29 30 /** 31 * Create a SET containing multiple objects. 32 * @param v a vector of objects making up the set. 33 */ 34 public BERSet( 35 ASN1EncodableVector v) 36 { 37 super(v, false); 38 } 39 40 /** 41 * Create a SET from an array of objects. 42 * @param a an array of ASN.1 objects. 43 */ 44 public BERSet( 45 ASN1Encodable[] a) 46 { 47 super(a, false); 48 } 49 50 int encodedLength() 51 throws IOException 52 { 53 int length = 0; 54 for (Enumeration e = getObjects(); e.hasMoreElements();) 55 { 56 length += ((ASN1Encodable)e.nextElement()).toASN1Primitive().encodedLength(); 57 } 58 59 return 2 + length + 2; 60 } 61 62 void encode( 63 ASN1OutputStream out) 64 throws IOException 65 { 66 out.write(BERTags.SET | BERTags.CONSTRUCTED); 67 out.write(0x80); 68 69 Enumeration e = getObjects(); 70 while (e.hasMoreElements()) 71 { 72 out.writeObject((ASN1Encodable)e.nextElement()); 73 } 74 75 out.write(0x00); 76 out.write(0x00); 77 } 78 }