1package org.bouncycastle.asn1;
2
3import java.io.IOException;
4
5/**
6 * Parser for indefinite-length SETs.
7 */
8public class BERSetParser
9    implements ASN1SetParser
10{
11    private ASN1StreamParser _parser;
12
13    BERSetParser(ASN1StreamParser parser)
14    {
15        this._parser = parser;
16    }
17
18    /**
19     * Read the next object in the SET.
20     *
21     * @return the next object in the SET, null if there are no more.
22     * @throws IOException if there is an issue reading the underlying stream.
23     */
24    public ASN1Encodable readObject()
25        throws IOException
26    {
27        return _parser.readObject();
28    }
29
30    /**
31     * Return an in-memory, encodable, representation of the SET.
32     *
33     * @return a BERSet.
34     * @throws IOException if there is an issue loading the data.
35     */
36    public ASN1Primitive getLoadedObject()
37        throws IOException
38    {
39        return new BERSet(_parser.readVector());
40    }
41
42    /**
43     * Return an BERSet representing this parser and its contents.
44     *
45     * @return an BERSet
46     */
47    public ASN1Primitive toASN1Primitive()
48    {
49        try
50        {
51            return getLoadedObject();
52        }
53        catch (IOException e)
54        {
55            throw new ASN1ParsingException(e.getMessage(), e);
56        }
57    }
58}