org.metastatic.jessie.pki.der

Class DERReader

Implemented Interfaces:
DER

public class DERReader
extends java.lang.Object
implements DER

This class decodes DER sequences into Java objects. The methods of this class do not have knowledge of higher-levels of structure in the DER stream -- such as ASN.1 constructions -- and it is therefore up to the calling application to determine if the data are structured properly by inspecting the DERValue that is returned.
Author:
Casey Marshall (rsdio@metastatic.org)

Field Summary

protected ByteArrayOutputStream
encBuf
protected InputStream
in

Fields inherited from interface org.metastatic.jessie.pki.der.DER

ANY, APPLICATION, BIT_STRING, BMP_STRING, BOOLEAN, CONSTRUCTED, CONSTRUCTED_VALUE, CONTEXT, ENUMERATED, GENERALIZED_TIME, GENERAL_STRING, GRAPHIC_STRING, IA5_STRING, INTEGER, ISO646_STRING, NULL, NUMERIC_STRING, OBJECT_IDENTIFIER, OCTET_STRING, PRE_ENCODED, PRINTABLE_STRING, PRIVATE, REAL, RELATIVE_OID, SEQUENCE, SET, T61_STRING, UNIVERSAL, UNIVERSAL_STRING, UTC_TIME, UTF8_STRING, VIDEOTEX_STRING

Constructor Summary

DERReader(InputStream in)
Create a new DER readed from an input stream.
DERReader(byte[] in)
Create a new DER reader from a byte array.

Method Summary

DERValue
read()
Decode a single value from the input stream, returning it in a new DERValue.
static DERValue
read(byte[] encoded)
Convenience method for reading a single primitive value from the given byte array.
void
skip(int len)

Field Details

encBuf

protected final ByteArrayOutputStream encBuf

in

protected InputStream in

Constructor Details

DERReader

public DERReader(InputStream in)
Create a new DER readed from an input stream.
Parameters:
in - The encoded bytes.

DERReader

public DERReader(byte[] in)
Create a new DER reader from a byte array.
Parameters:
in - The encoded bytes.

Method Details

read

public DERValue read()
            throws IOException
Decode a single value from the input stream, returning it in a new DERValue. By "single value" we mean any single type in its entirety -- including constructed types such as SEQUENCE and all the values they contain. Usually it is sufficient to call this method once to parse and return the top-level structure, then to inspect the returned value for the proper contents.
Returns:
The parsed DER structure.

read

public static DERValue read(byte[] encoded)
            throws IOException
Convenience method for reading a single primitive value from the given byte array.
Parameters:
encoded - The encoded bytes.

skip

public void skip(int len)
            throws IOException