|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
java.io.FilterInputStream
org.demac.impl.j2me.process.base.service.webservices.asn1.DERDecoder
public class DERDecoder
Constructor Summary | |
---|---|
DERDecoder(java.io.InputStream in)
Creates an instance that reads from the given input stream. |
|
DERDecoder(java.io.InputStream in,
int limit)
Creates an instance that reads from the given input stream, and enforces the given maximum number of input octets to the decoder. |
Method Summary | |
---|---|
int |
available()
Returns the number of bytes that can be read from the underlying stream without blocking. |
void |
close()
This method closes the underlying stream. |
static java.lang.Class |
getClass(int tag)
Returns the class that is representing the ASN.1 type with the given tag. |
int |
getInputLimit()
|
boolean |
isBody()
|
boolean |
isDebug()
|
void |
mark(int readAheadLimit)
This method calls the corresponding method of the underlying stream and also marks this stream's position, which denotes the overall number of octets already read from this stream. |
boolean |
markSupported()
Returns true iff the underlying stream supports marking of
stream positions. |
int |
read()
This method calls the corresponding method of the underlying stream and increases the position counter by the number of octets actually read. |
int |
read(byte[] b)
This method calls the corresponding method of the underlying stream and increases the position counter by the number of octets actually read. |
int |
read(byte[] b,
int off,
int len)
This method calls the corresponding method of the underlying stream and increases the position counter by the number of octets actually read. |
int |
readBase128()
Reads a base 128 number from this input stream. |
int |
readBase256(int num)
This method reads in an decodes a number in base 256 format. |
void |
readBitString(ASN1BitString t)
|
void |
readBoolean(ASN1Boolean t)
|
void |
readChoice(ASN1Choice t)
Reads an ASN.1 CHOICE type. |
void |
readCollection(ASN1Collection t)
|
void |
readCollectionOf(ASN1CollectionOf t)
|
ASN1Sequence |
readContent()
|
ASN1Sequence |
readIdentifier()
|
void |
readInteger(ASN1Integer t)
|
boolean |
readNext()
Reads the next identifier and length octets from the stream and decodes them if skip_ is
false . |
void |
readNull(ASN1Null t)
|
void |
readObjectIdentifier(ASN1ObjectIdentifier t)
|
void |
readOctetString(ASN1OctetString t)
|
void |
readReal(ASN1Real t)
|
void |
readString(ASN1String t)
|
void |
readTaggedType(ASN1TaggedType t)
This method also reads in ASN1Opaque types. |
void |
readTime(ASN1Time t)
|
ASN1Type |
readType()
Reads the next ASN.1 type in the stream. |
void |
readType(ASN1Type t)
|
void |
reset()
Resets the unerlying input stream to the last marked position and also resets this stream's position to the last marked one. |
void |
setDebug(boolean debug)
|
void |
setInputLimit(int limit)
Sets the maximum number of input octets read from the underlying stream. |
long |
skip(long n)
This method calls the corresponding method of the underlying stream and increases the position counter by the number of octets actually skipped. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DERDecoder(java.io.InputStream in)
in
- The input stream to read from.public DERDecoder(java.io.InputStream in, int limit)
in
- The input stream to read from.limit
- The maximum number of octets allowed in the input stream.
A value of 0 disables checking of upper limits.Method Detail |
---|
public static java.lang.Class getClass(int tag) throws ASN1Exception
tag
- The ASN.1 tag of the class to be returned.
ASN1Exception
- if no implementing class is known for the given tag.
java.lang.IllegalArgumentException
- if the given tag is negative.public void setInputLimit(int limit)
Setting limits prevents DoS attacks on cryptographic services that handle ASN.1/DER/BER input. Such code might be tricked into allocating insane amounts of buffer memory to decode a structure with forged length octets, which might result in out of memory errors. Such code should enforce a reasonable upper bound on the size of processed input structures.
limit
- The maximum number of octets allowed when readinginput.public int getInputLimit()
public void setDebug(boolean debug)
public boolean isDebug()
public boolean readNext() throws ASN1Exception, java.io.IOException
skip_
is
false
.
The resulting values are written to tag_
,
tagclass_
, primitive_
,
length_
, and indefinite_
.
If the stream is at its end then false
is returned and
true
else. If skip_
is true
then nothing is read and true
is returned.
This method does not enforce DER, it can be used to parse BER as well. In other words, calling methods have to check for indefinite length encodings.
true
if the next header was read.
ASN1Exception
java.io.IOException
public ASN1Type readType() throws ASN1Exception, java.io.IOException
null
is returned. EOC marks the end of
indefinite length encodings.
readType
in interface Decoder
null
if the
type is EOC.
ASN1Exception
java.io.IOException
public void readType(ASN1Type t) throws ASN1Exception, java.io.IOException
readType
in interface Decoder
ASN1Exception
java.io.IOException
public void readBoolean(ASN1Boolean t) throws ASN1Exception, java.io.IOException
readBoolean
in interface Decoder
ASN1Exception
java.io.IOException
public void readInteger(ASN1Integer t) throws ASN1Exception, java.io.IOException
readInteger
in interface Decoder
ASN1Exception
java.io.IOException
public void readBitString(ASN1BitString t) throws ASN1Exception, java.io.IOException
readBitString
in interface Decoder
ASN1Exception
java.io.IOException
public void readOctetString(ASN1OctetString t) throws ASN1Exception, java.io.IOException
readOctetString
in interface Decoder
ASN1Exception
java.io.IOException
public void readNull(ASN1Null t) throws ASN1Exception, java.io.IOException
readNull
in interface Decoder
ASN1Exception
java.io.IOException
public void readObjectIdentifier(ASN1ObjectIdentifier t) throws ASN1Exception, java.io.IOException
readObjectIdentifier
in interface Decoder
ASN1Exception
java.io.IOException
public boolean isBody()
public ASN1Sequence readIdentifier()
public ASN1Sequence readContent()
public void readReal(ASN1Real t) throws ASN1Exception, java.io.IOException
readReal
in interface Decoder
ASN1Exception
java.io.IOException
public void readString(ASN1String t) throws ASN1Exception, java.io.IOException
readString
in interface Decoder
ASN1Exception
java.io.IOException
public void readCollection(ASN1Collection t) throws ASN1Exception, java.io.IOException
readCollection
in interface Decoder
ASN1Exception
java.io.IOException
public void readCollectionOf(ASN1CollectionOf t) throws ASN1Exception, java.io.IOException
readCollectionOf
in interface Decoder
ASN1Exception
java.io.IOException
public void readTime(ASN1Time t) throws ASN1Exception, java.io.IOException
readTime
in interface Decoder
ASN1Exception
java.io.IOException
public void readTaggedType(ASN1TaggedType t) throws ASN1Exception, java.io.IOException
ASN1Opaque
types. Opaque
types take on the tag and tag class of the decoded type and read in the
contents octets into an OCTET STRING. The opaque type can seamlessly be
encoded back into the original encoding. No traversal of the inner
structure of the encoded type is required.
readTaggedType
in interface Decoder
t
- The ASN1TaggedType
or
ASN1Opaque
to decode.
ASN1Exception
java.io.IOException
public void readChoice(ASN1Choice t) throws ASN1Exception, java.io.IOException
ASN1Choice
instance. The choice must be unambiguous.
The CHOICE elements must be tagged EXPLICIT. Otherwise, the
decoding will abort with an exception. The ASN1Choice
class assures this condition upon adding alternative types to the CHOICE
type.
readChoice
in interface Decoder
t
- The collection of choices from which the correct needs to
be selected.
ASN1Exception
java.io.IOException
public int readBase128() throws ASN1Exception, java.io.IOException
This method is used for reading e.g. the long form of ASN.1 tags.
However, only tags up to the int
range are supported.
Note: tags longer than that are not detected, but a wrong number
is being returned.
ASN1Exception
- iff the end of the data is reached before the number is
decoded.
java.io.IOException
- iff guess what...public int readBase256(int num) throws ASN1Exception, java.io.IOException
long
range are supported. Even that is probably too
much since we'll hardly have to account for computers with more than 264
bytes of memory, right?
The number is expected to be num
bytes long. Certain bad
encodings are tolerated by this implementation and may lead to errors in
rare cases. For instance this implementation does not throw an error if
the number of octets of the encoded number is not minimal (e.g. has
leading zeroes). Hence, the re-encoding of such a decoded number will
result in an encoding that is not identical to the original one.
num
- The number of octets of the base 256 number to read from
the input stream.
ASN1Exception
- iff the end of the stream is reached before the number
could be decoded completely.
java.io.IOException
public int read() throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public int read(byte[] b) throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public long skip(long n) throws java.io.IOException
skip
in class java.io.FilterInputStream
java.io.IOException
public void mark(int readAheadLimit)
mark
in class java.io.FilterInputStream
readAheadLimit
- The maximum number of bytes that can be read and still
reset to the marked position.public void reset() throws java.io.IOException
reset
in class java.io.FilterInputStream
java.io.IOException
public boolean markSupported()
true
iff the underlying stream supports marking of
stream positions. This should better be the case, otherwise an exception
is raised when objects or headers are read from this stream.
markSupported
in class java.io.FilterInputStream
true
if marking is supported by the underlying
stream.public int available() throws java.io.IOException
available
in class java.io.FilterInputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.FilterInputStream
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |