1package org.bouncycastle.asn1;
2
3import java.io.IOException;
4import java.util.Enumeration;
5
6class LazyConstructionEnumeration
7    implements Enumeration
8{
9    private ASN1InputStream aIn;
10    private Object          nextObj;
11
12    public LazyConstructionEnumeration(byte[] encoded)
13    {
14        aIn = new ASN1InputStream(encoded, true);
15        nextObj = readObject();
16    }
17
18    public boolean hasMoreElements()
19    {
20        return nextObj != null;
21    }
22
23    public Object nextElement()
24    {
25        Object o = nextObj;
26
27        nextObj = readObject();
28
29        return o;
30    }
31
32    private Object readObject()
33    {
34        try
35        {
36            return aIn.readObject();
37        }
38        catch (IOException e)
39        {
40            throw new ASN1ParsingException("malformed DER construction: " + e, e);
41        }
42    }
43}
44