DerInputStream

A DER input stream, used for parsing ASN.1 DER-encoded data such as that found in X.509 certificates. DER is a subset of BER/1, which has the advantage that it allows only a single encoding of primitive data. (High level data such as dates still support many encodings.) That is, it uses the "Definite" Encoding Rules (DER) not the "Basic" ones (BER).

<P>Note that, like BER/1, DER streams are streams of explicitly tagged data values. Accordingly, this programming interface does not expose any variant of the java.io.InputStream interface, since that kind of input stream holds untagged data values and using that I/O model could prevent correct parsing of the DER data.

<P>At this time, this class supports only a subset of the types of DER data encodings which are defined. That subset is sufficient for parsing most X.509 certificates.

More...

Constructors

this
this(byte[] data)

Create a DER input stream from a data buffer. The buffer is not copied, it is shared. Accordingly, the buffer should be treated as read-only.

this
this(byte[] data, int offset, int len, bool allowBER)

Create a DER input stream from part of a data buffer with additional arg to control whether DER checks are enforced. The buffer is not copied, it is shared. Accordingly, the buffer should be treated as read-only.

this
this(byte[] data, int offset, int len)

Create a DER input stream from part of a data buffer. The buffer is not copied, it is shared. Accordingly, the buffer should be treated as read-only.

this
this(DerInputBuffer buf)
Undocumented in source.

Members

Functions

available
int available()

Returns the number of bytes available for reading. This is most useful for testing whether the stream is empty.

getBMPString
string getBMPString()

Read a string that was encoded as a BMPString DER value.

getBigInteger
BigInteger getBigInteger()

Get a integer from the input stream as a BigInteger object.

getBitString
byte[] getBitString()

Get a bit string from the input stream. Padded bits (if any) will be stripped off before the bit string is returned.

getByte
int getByte()

Get a Generalized encoded time value from the input stream.

getBytes
void getBytes(byte[] val)

Returns the asked number of bytes from the input stream.

getDerValue
DerValue getDerValue()

Get a single DER-encoded value from the input stream. It can often be useful to pull a value from the stream and defer parsing it. For example, you can pull a nested sequence out with one call, and only examine its elements later when you really need to.

getEnumerated
int getEnumerated()

Get an enumerated from the input stream.

getGeneralString
string getGeneralString()

Read a string that was encoded as a GeneralString DER value.

getIA5String
string getIA5String()

Read a string that was encoded as a IA5tring DER value.

getInteger
int getInteger()

Get an integer from the input stream as an integer.

getLength
int getLength()
Undocumented in source. Be warned that the author may not have intended to support it.
getNull
void getNull()

Reads an encoded null value from the input stream.

getOctetString
byte[] getOctetString()

Returns an ASN.1 OCTET STRING from the input stream.

getPositiveBigInteger
BigInteger getPositiveBigInteger()

Returns an ASN.1 INTEGER value as a positive BigInteger. This is just to deal with implementations that incorrectly encode some values as negative.

getPrintableString
string getPrintableString()

Read a string that was encoded as a PrintableString DER value.

getSequence
DerValue[] getSequence(int startLen)

Return a sequence of encoded entities. ASN.1 sequences are ordered, and they are often used, like a "struct" in C or C++, to group data values. They may have optional or context specific values.

getSet
DerValue[] getSet(int startLen)

Return a set of encoded entities. ASN.1 sets are unordered, though DER may specify an order for some kinds of sets (such as the attributes in an X.500 relative distinguished name) to facilitate binary comparisons of encoded values.

getSet
DerValue[] getSet(int startLen, bool implicit)

Return a set of encoded entities. ASN.1 sets are unordered, though DER may specify an order for some kinds of sets (such as the attributes in an X.500 relative distinguished name) to facilitate binary comparisons of encoded values.

getT61String
string getT61String()

Read a string that was encoded as a T61String DER value.

getUTF8String
string getUTF8String()

Read a string that was encoded as a UTF8String DER value.

getUnalignedBitString
BitArray getUnalignedBitString()

Get a bit string from the input stream. The bit string need not be byte-aligned.

mark
void mark(int value)

Mark the current position in the buffer, so that a later call to <code>reset</code> will return here.

peekByte
int peekByte()
Undocumented in source. Be warned that the author may not have intended to support it.
readVector
DerValue[] readVector(int startLen)
Undocumented in source. Be warned that the author may not have intended to support it.
reset
void reset()

Return to the position of the last <code>mark</code> call. A mark is implicitly set at the beginning of the stream when it is created.

subStream
DerInputStream subStream(int len, bool do_skip)

Creates a new DER input stream from part of this input stream.

toByteArray
byte[] toByteArray()

Return what has been written to this DerInputStream as a byte array. Useful for debugging.

Static functions

getLength
int getLength(InputStream stream)
Undocumented in source. Be warned that the author may not have intended to support it.
getLength
int getLength(int lenByte, InputStream stream)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

buffer
DerInputBuffer buffer;
Undocumented in source.
tag
byte tag;

The DER tag of the value; one of the tag_ constants.

Detailed Description

@author David Brownell @author Amit Kapoor @author Hemma Prafullchandra

Meta