public class DerInputStream
extends java.lang.Object
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.
| Constructor and Description |
|---|
DerInputStream(byte[] data) |
DerInputStream(byte[] data,
int offset,
int len) |
DerInputStream(byte[] data,
int start,
int length,
boolean allowBER)
Constructs a DerInputStream by assigning all its fields.
|
| Modifier and Type | Method and Description |
|---|---|
void |
atEnd()
Ensures there is no more data.
|
int |
available()
Returns the number of bytes available for reading.
|
java.math.BigInteger |
getBigInteger() |
byte[] |
getBitString() |
java.lang.String |
getBMPString() |
DerValue |
getDerValue()
Reads a DerValue from this stream.
|
int |
getEnumerated() |
java.util.Date |
getGeneralizedTime() |
java.lang.String |
getGeneralString() |
java.lang.String |
getIA5String() |
int |
getInteger() |
void |
getNull() |
byte[] |
getOctetString() |
ObjectIdentifier |
getOID() |
java.util.Optional<DerValue> |
getOptional(byte tag)
Returns the next DerValue if its tag is the given one.
|
java.util.Optional<DerValue> |
getOptionalExplicitContextSpecific(int n)
Returns the inner DerValue if the next DerValue is
an EXPLICIT context-specific value tagged by
n. |
java.util.Optional<DerValue> |
getOptionalImplicitContextSpecific(int n,
byte tag)
Returns the restored DerValue if the next DerValue is
an IMPLICIT context-specific value tagged by
n. |
java.math.BigInteger |
getPositiveBigInteger() |
java.lang.String |
getPrintableString() |
DerValue[] |
getSequence(int startLen) |
DerValue[] |
getSet(int startLen) |
DerValue[] |
getSet(int startLen,
boolean implicit) |
java.lang.String |
getT61String() |
BitArray |
getUnalignedBitString() |
java.util.Date |
getUTCTime() |
java.lang.String |
getUTF8String() |
void |
mark(int readAheadLimit)
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. |
boolean |
seeOptionalContextSpecific(int n)
Detect if the next DerValue is a context-specific value
tagged by
n. |
byte[] |
toByteArray()
Returns the remaining unread bytes, or, all bytes if none read yet.
|
public DerInputStream(byte[] data,
int start,
int length,
boolean allowBER)
data should never be null even if length is 0.public DerInputStream(byte[] data)
throws java.io.IOException
java.io.IOExceptionpublic DerInputStream(byte[] data,
int offset,
int len)
throws java.io.IOException
java.io.IOExceptionpublic byte[] toByteArray()
public DerValue getDerValue() throws java.io.IOException
java.io.IOException - if a DerValue cannot be constructed starting from
this position because of byte shortage or encoding error.public int getInteger()
throws java.io.IOException
java.io.IOExceptionpublic java.math.BigInteger getBigInteger()
throws java.io.IOException
java.io.IOExceptionpublic java.math.BigInteger getPositiveBigInteger()
throws java.io.IOException
java.io.IOExceptionpublic int getEnumerated()
throws java.io.IOException
java.io.IOExceptionpublic byte[] getBitString()
throws java.io.IOException
java.io.IOExceptionpublic BitArray getUnalignedBitString() throws java.io.IOException
java.io.IOExceptionpublic byte[] getOctetString()
throws java.io.IOException
java.io.IOExceptionpublic void getNull()
throws java.io.IOException
java.io.IOExceptionpublic ObjectIdentifier getOID() throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getUTF8String()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getPrintableString()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getT61String()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getBMPString()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getIA5String()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getGeneralString()
throws java.io.IOException
java.io.IOExceptionpublic java.util.Date getUTCTime()
throws java.io.IOException
java.io.IOExceptionpublic java.util.Date getGeneralizedTime()
throws java.io.IOException
java.io.IOExceptionpublic DerValue[] getSequence(int startLen) throws java.io.IOException
java.io.IOExceptionpublic DerValue[] getSet(int startLen) throws java.io.IOException
java.io.IOExceptionpublic DerValue[] getSet(int startLen, boolean implicit) throws java.io.IOException
java.io.IOExceptionpublic int peekByte()
throws java.io.IOException
java.io.IOExceptionpublic void mark(int readAheadLimit)
reset will return here.
The readAheadLimit is useless here, because
all data is available, and we can go to anywhere at will.public void reset()
mark
call. A mark is implicitly set at the beginning of
the stream when it is created.public int available()
public void atEnd()
throws java.io.IOException
java.io.IOException - if the end is NOT reached yetpublic java.util.Optional<DerValue> getOptional(byte tag) throws java.io.IOException
tag - the expected tagjava.io.IOException - if an I/O error happenspublic boolean seeOptionalContextSpecific(int n)
throws java.io.IOException
n.n - the expected tagjava.io.IOException - if an I/O error happens while peeking the bytepublic java.util.Optional<DerValue> getOptionalExplicitContextSpecific(int n) throws java.io.IOException
n.n - the expected tagjava.io.IOException - if an I/O error happenspublic java.util.Optional<DerValue> getOptionalImplicitContextSpecific(int n, byte tag) throws java.io.IOException
n.n - the expected tagtag - the real tag for the IMPLICIT typejava.io.IOException - if an I/O error happens