1 package org.bouncycastle.asn1; 2 3 import java.io.IOException; 4 import java.util.Enumeration; 5 6 public class LazyDERSequence 7 extends DERSequence 8 { 9 private byte[] encoded; 10 private boolean parsed = false; 11 private int size = -1; 12 13 LazyDERSequence( 14 byte[] encoded) 15 throws IOException 16 { 17 this.encoded = encoded; 18 } 19 20 private void parse() 21 { 22 Enumeration en = new LazyDERConstructionEnumeration(encoded); 23 24 while (en.hasMoreElements()) 25 { 26 addObject((DEREncodable)en.nextElement()); 27 } 28 29 parsed = true; 30 } 31 32 public synchronized DEREncodable getObjectAt(int index) 33 { 34 if (!parsed) 35 { 36 parse(); 37 } 38 39 return super.getObjectAt(index); 40 } 41 42 public synchronized Enumeration getObjects() 43 { 44 if (parsed) 45 { 46 return super.getObjects(); 47 } 48 49 return new LazyDERConstructionEnumeration(encoded); 50 } 51 52 public int size() 53 { 54 if (size < 0) 55 { 56 Enumeration en = new LazyDERConstructionEnumeration(encoded); 57 58 size = 0; 59 while (en.hasMoreElements()) 60 { 61 en.nextElement(); 62 size++; 63 } 64 } 65 66 return size; 67 } 68 69 void encode( 70 DEROutputStream out) 71 throws IOException 72 { 73 out.writeEncoded(SEQUENCE | CONSTRUCTED, encoded); 74 } 75 } 76