public class

DerInputStream

extends Object
java.lang.Object
   ↳ sun.security.util.DerInputStream

Class Overview

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).

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.

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.

Summary

Fields
public byte tag The DER tag of the value; one of the tag_ constants.
Public Constructors
DerInputStream(byte[] data)
Create a DER input stream from a data buffer.
DerInputStream(byte[] data, int offset, int len)
Create a DER input stream from part of a data buffer.
Public Methods
int available()
Returns the number of bytes available for reading.
String getBMPString()
Read a string that was encoded as a BMPString DER value.
BigInteger getBigInteger()
Get a integer from the input stream as a BigInteger object.
byte[] getBitString()
Get a bit string from the input stream.
void getBytes(byte[] val)
Returns the asked number of bytes from the input stream.
DerValue getDerValue()
Get a single DER-encoded value from the input stream.
int getEnumerated()
Get an enumerated from the input stream.
String getGeneralString()
Read a string that was encoded as a GeneralString DER value.
Date getGeneralizedTime()
Get a Generalized encoded time value from the input stream.
String getIA5String()
Read a string that was encoded as a IA5tring DER value.
int getInteger()
Get an integer from the input stream as an integer.
void getNull()
Reads an encoded null value from the input stream.
ObjectIdentifier getOID()
Reads an X.200 style Object Identifier from the stream.
byte[] getOctetString()
Returns an ASN.1 OCTET STRING from the input stream.
BigInteger getPositiveBigInteger()
Returns an ASN.1 INTEGER value as a positive BigInteger.
String getPrintableString()
Read a string that was encoded as a PrintableString DER value.
DerValue[] getSequence(int startLen)
Return a sequence of encoded entities.
DerValue[] getSet(int startLen, boolean implicit)
Return a set of encoded entities.
DerValue[] getSet(int startLen)
Return a set of encoded entities.
String getT61String()
Read a string that was encoded as a T61String DER value.
Date getUTCTime()
Get a UTC encoded time value from the input stream.
String getUTF8String()
Read a string that was encoded as a UTF8String DER value.
BitArray getUnalignedBitString()
Get a bit string from the input stream.
void mark(int value)
Mark the current position in the buffer, so that a later call to reset will return here.
int peekByte()
void reset()
Return to the position of the last mark call.
DerInputStream subStream(int len, boolean do_skip)
Creates a new DER input stream from part of this input stream.
byte[] toByteArray()
Return what has been written to this DerInputStream as a byte array.
Protected Methods
DerValue[] readVector(int startLen)
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public byte tag

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

Public Constructors

public DerInputStream (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.

Parameters
data the buffer from which to create the string (CONSUMED)
Throws
IOException

public DerInputStream (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.

Parameters
data the buffer from which to create the string (CONSUMED)
offset the first index of data which will be read as DER input in the new stream
len how long a chunk of the buffer to use, starting at "offset"
Throws
IOException

Public Methods

public int available ()

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

public String getBMPString ()

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

Throws
IOException

public BigInteger getBigInteger ()

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

Returns
  • the integer held in this DER input stream.
Throws
IOException

public byte[] getBitString ()

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

Throws
IOException

public void getBytes (byte[] val)

Returns the asked number of bytes from the input stream.

Throws
IOException

public 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.

Throws
IOException

public int getEnumerated ()

Get an enumerated from the input stream.

Returns
  • the integer held in this DER input stream.
Throws
IOException

public String getGeneralString ()

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

Throws
IOException

public Date getGeneralizedTime ()

Get a Generalized encoded time value from the input stream.

Throws
IOException

public String getIA5String ()

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

Throws
IOException

public int getInteger ()

Get an integer from the input stream as an integer.

Returns
  • the integer held in this DER input stream.
Throws
IOException

public void getNull ()

Reads an encoded null value from the input stream.

Throws
IOException

public ObjectIdentifier getOID ()

Reads an X.200 style Object Identifier from the stream.

Throws
IOException

public byte[] getOctetString ()

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

Throws
IOException

public 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.

Returns
  • the integer held in this DER value as a BigInteger.
Throws
IOException

public String getPrintableString ()

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

Throws
IOException

public 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.

Parameters
startLen guess about how long the sequence will be (used to initialize an auto-growing data structure)
Returns
  • array of the values in the sequence
Throws
IOException

public DerValue[] getSet (int startLen, boolean 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.

Parameters
startLen guess about how large the set will be (used to initialize an auto-growing data structure)
implicit if true tag is assumed implicit.
Returns
  • array of the values in the sequence
Throws
IOException

public 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.

Parameters
startLen guess about how large the set will be (used to initialize an auto-growing data structure)
Returns
  • array of the values in the sequence
Throws
IOException

public String getT61String ()

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

Throws
IOException

public Date getUTCTime ()

Get a UTC encoded time value from the input stream.

Throws
IOException

public String getUTF8String ()

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

Throws
IOException

public BitArray getUnalignedBitString ()

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

Throws
IOException

public void mark (int value)

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

public int peekByte ()

Throws
IOException

public void reset ()

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

public DerInputStream subStream (int len, boolean do_skip)

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

Parameters
len how long a chunk of the current input stream to use, starting at the current position.
do_skip true if the existing data in the input stream should be skipped. If this value is false, the next data read on this stream and the newly created stream will be the same.
Throws
IOException

public byte[] toByteArray ()

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

Protected Methods

protected DerValue[] readVector (int startLen)

Throws
IOException