001package org.apache.commons.ssl.org.bouncycastle.asn1; 002 003import java.io.IOException; 004import java.util.Enumeration; 005 006public class BERSet 007 extends ASN1Set 008{ 009 /** 010 * create an empty sequence 011 */ 012 public BERSet() 013 { 014 } 015 016 /** 017 * @param obj - a single object that makes up the set. 018 */ 019 public BERSet( 020 ASN1Encodable obj) 021 { 022 super(obj); 023 } 024 025 /** 026 * @param v - a vector of objects making up the set. 027 */ 028 public BERSet( 029 ASN1EncodableVector v) 030 { 031 super(v, false); 032 } 033 034 /** 035 * create a set from an array of objects. 036 */ 037 public BERSet( 038 ASN1Encodable[] a) 039 { 040 super(a, false); 041 } 042 043 int encodedLength() 044 throws IOException 045 { 046 int length = 0; 047 for (Enumeration e = getObjects(); e.hasMoreElements();) 048 { 049 length += ((ASN1Encodable)e.nextElement()).toASN1Primitive().encodedLength(); 050 } 051 052 return 2 + length + 2; 053 } 054 055 /* 056 */ 057 void encode( 058 ASN1OutputStream out) 059 throws IOException 060 { 061 out.write(BERTags.SET | BERTags.CONSTRUCTED); 062 out.write(0x80); 063 064 Enumeration e = getObjects(); 065 while (e.hasMoreElements()) 066 { 067 out.writeObject((ASN1Encodable)e.nextElement()); 068 } 069 070 out.write(0x00); 071 out.write(0x00); 072 } 073}