1package org.bouncycastle.asn1;
2
3import java.io.IOException;
4
5/**
6 * Parser DER EXTERNAL tagged objects.
7 */
8public class DERExternalParser
9    implements ASN1Encodable, InMemoryRepresentable
10{
11    private ASN1StreamParser _parser;
12
13    /**
14     * Base constructor.
15     *
16     * @param parser the underlying parser to read the DER EXTERNAL from.
17     */
18    public DERExternalParser(ASN1StreamParser parser)
19    {
20        this._parser = parser;
21    }
22
23    public ASN1Encodable readObject()
24        throws IOException
25    {
26        return _parser.readObject();
27    }
28
29    /**
30     * Return an in-memory, encodable, representation of the EXTERNAL object.
31     *
32     * @return a DERExternal.
33     * @throws IOException if there is an issue loading the data.
34     */
35    public ASN1Primitive getLoadedObject()
36        throws IOException
37    {
38        try
39        {
40            return new DERExternal(_parser.readVector());
41        }
42        catch (IllegalArgumentException e)
43        {
44            throw new ASN1Exception(e.getMessage(), e);
45        }
46    }
47
48    /**
49     * Return an DERExternal representing this parser and its contents.
50     *
51     * @return an DERExternal
52     */
53    public ASN1Primitive toASN1Primitive()
54    {
55        try
56        {
57            return getLoadedObject();
58        }
59        catch (IOException ioe)
60        {
61            throw new ASN1ParsingException("unable to get DER object", ioe);
62        }
63        catch (IllegalArgumentException ioe)
64        {
65            throw new ASN1ParsingException("unable to get DER object", ioe);
66        }
67    }
68}