001package org.apache.commons.ssl.org.bouncycastle.asn1; 002 003import java.io.IOException; 004import java.util.Enumeration; 005 006public class BERSequence 007 extends ASN1Sequence 008{ 009 /** 010 * create an empty sequence 011 */ 012 public BERSequence() 013 { 014 } 015 016 /** 017 * create a sequence containing one object 018 */ 019 public BERSequence( 020 ASN1Encodable obj) 021 { 022 super(obj); 023 } 024 025 /** 026 * create a sequence containing a vector of objects. 027 */ 028 public BERSequence( 029 ASN1EncodableVector v) 030 { 031 super(v); 032 } 033 034 /** 035 * create a sequence containing an array of objects. 036 */ 037 public BERSequence( 038 ASN1Encodable[] array) 039 { 040 super(array); 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.SEQUENCE | 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}