1 package org.bouncycastle.asn1; 2 3 import java.io.IOException; 4 5 /** 6 * Indefinite length SEQUENCE of objects. 7 * <p> 8 * Length field has value 0x80, and the sequence ends with two bytes of: 0x00, 0x00. 9 * </p><p> 10 * For X.690 syntax rules, see {@link ASN1Sequence}. 11 * </p> 12 */ 13 public class BERSequence 14 extends ASN1Sequence 15 { 16 /** 17 * Create an empty sequence 18 */ BERSequence()19 public BERSequence() 20 { 21 } 22 23 /** 24 * Create a sequence containing one object 25 */ BERSequence(ASN1Encodable element)26 public BERSequence(ASN1Encodable element) 27 { 28 super(element); 29 } 30 31 /** 32 * Create a sequence containing a vector of objects. 33 */ BERSequence(ASN1EncodableVector elementVector)34 public BERSequence(ASN1EncodableVector elementVector) 35 { 36 super(elementVector); 37 } 38 39 /** 40 * Create a sequence containing an array of objects. 41 */ BERSequence(ASN1Encodable[] elements)42 public BERSequence(ASN1Encodable[] elements) 43 { 44 super(elements); 45 } 46 encodedLength()47 int encodedLength() throws IOException 48 { 49 int count = elements.length; 50 int totalLength = 0; 51 52 for (int i = 0; i < count; ++i) 53 { 54 ASN1Primitive p = elements[i].toASN1Primitive(); 55 totalLength += p.encodedLength(); 56 } 57 58 return 2 + totalLength + 2; 59 } 60 encode(ASN1OutputStream out, boolean withTag)61 void encode(ASN1OutputStream out, boolean withTag) throws IOException 62 { 63 out.writeEncodedIndef(withTag, BERTags.SEQUENCE | BERTags.CONSTRUCTED, elements); 64 } 65 } 66