001package org.apache.commons.ssl.org.bouncycastle.asn1;
002
003import java.io.IOException;
004
005public class DERExternalParser
006    implements ASN1Encodable, InMemoryRepresentable
007{
008    private ASN1StreamParser _parser;
009
010    /**
011     * 
012     */
013    public DERExternalParser(ASN1StreamParser parser)
014    {
015        this._parser = parser;
016    }
017
018    public ASN1Encodable readObject()
019        throws IOException
020    {
021        return _parser.readObject();
022    }
023
024    public ASN1Primitive getLoadedObject()
025        throws IOException
026    {
027        try
028        {
029            return new DERExternal(_parser.readVector());
030        }
031        catch (IllegalArgumentException e)
032        {
033            throw new ASN1Exception(e.getMessage(), e);
034        }
035    }
036    
037    public ASN1Primitive toASN1Primitive()
038    {
039        try 
040        {
041            return getLoadedObject();
042        }
043        catch (IOException ioe) 
044        {
045            throw new ASN1ParsingException("unable to get DER object", ioe);
046        }
047        catch (IllegalArgumentException ioe) 
048        {
049            throw new ASN1ParsingException("unable to get DER object", ioe);
050        }
051    }
052}