001package org.apache.commons.ssl.org.bouncycastle.asn1;
002
003import java.io.IOException;
004import java.util.Enumeration;
005
006class LazyConstructionEnumeration
007    implements Enumeration
008{
009    private ASN1InputStream aIn;
010    private Object          nextObj;
011
012    public LazyConstructionEnumeration(byte[] encoded)
013    {
014        aIn = new ASN1InputStream(encoded, true);
015        nextObj = readObject();
016    }
017
018    public boolean hasMoreElements()
019    {
020        return nextObj != null;
021    }
022
023    public Object nextElement()
024    {
025        Object o = nextObj;
026
027        nextObj = readObject();
028
029        return o;
030    }
031
032    private Object readObject()
033    {
034        try
035        {
036            return aIn.readObject();
037        }
038        catch (IOException e)
039        {
040            throw new ASN1ParsingException("malformed DER construction: " + e, e);
041        }
042    }
043}