|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
This interface defines a generic decoder to unmarshal ASN.1 values.
| Method Summary | |
byte[] |
decodeAny()
|
void |
decodeAny(OutputStream out)
Decodes an ASN.1 (ANY) value and copies it to the specified output stream. |
BitString |
decodeBitString()
Decodes an ASN.1 BIT STRING value from the underlying stream and returns it as a BitString value. |
BitString |
decodeBitString(BitString set)
Decodes an ASN.1 BIT STRING value from the underlying stream and appends its bit values to the specified BitString. |
String |
decodeBMPString()
Decodes an ASN.1 BMPString value from the underlying input stream and return it as a String object. |
StringBuffer |
decodeBMPString(StringBuffer buf)
Decodes an ASN.1 BMPString value from the underlying stream and appends its string representation to the specified StringBuffer. |
boolean |
decodeBoolean()
Decodes an ASN.1 BOOLEAN value from the underlying stream and returns it as a boolean value. |
int |
decodeChoice()
Starts the decoding of a BER encoded CHOICE value. |
int |
decodeConstructed(int tag)
Starts the decoding of a BER encoded ASN.1 constructed value. |
void |
decodeEndOf(int id)
Terminates the decoding of the constructed value identified by id is finished. |
BigInteger |
decodeEnumerated()
Decodes an ASN.1 ENUMERATED value from the underlying stream and returns it as a BigInteger value.
|
int |
decodeEnumeratedAsInt()
Decodes an ASN.1 ENUMERATED value from the underlying stream and returns it as a int value.
|
long |
decodeEnumeratedAsLong()
Decodes an ASN.1 ENUMERATED value from the underlying stream and returns it as a int value.
|
int |
decodeExplicit(int tag)
Indicates that the next decoded ASN.1 value has an explicit tag set equals to the specified tag value. |
Calendar |
decodeGeneralizedTime()
Decodes an ASN.1 GeneralizedTime value from the underlying input stream and return it as a Calendar object. |
String |
decodeIA5String()
Decodes an ASN.1 IA5String value from the underlying input stream and return it as a String object. |
StringBuffer |
decodeIA5String(StringBuffer buf)
Decodes an ASN.1 IA5String value from the underlying input stream and appends it to the specified StringBuffer. |
void |
decodeImplicit(int tag)
Indicates that the next value to be decoded has the specified implicit tag. |
BigInteger |
decodeInteger()
Decodes an ASN.1 INTEGER value from the underlying stream and returns it as a BigInteger value.
|
int |
decodeIntegerAsInt()
Decodes an ASN.1 INTEGER value from the underlying stream and returns it as a int value.
|
long |
decodeIntegerAsLong()
Decodes an ASN.1 INTEGER value from the underlying stream and returns it as a long value.
|
void |
decodeNull()
Decodes the next ASN.1 NULL value from the underlying stream. |
String |
decodeNumericString()
Decodes an ASN.1 NumericString value from the underlying input stream and return it as a String object. |
StringBuffer |
decodeNumericString(StringBuffer buf)
Decodes an ASN.1 NumericString value from the underlying input stream and appends it to the specified StringBuffer. |
ObjectIdentifier |
decodeObjectIdentifier()
Decodes a BER encoded OBJECT IDENTIFIER. |
byte[] |
decodeOctetString()
Decodes a BER encoded ASN.1 OCTET STRING value and returns it as a byte array. |
void |
decodeOctetString(OutputStream buf)
Decodes a BER encoded ASN.1 OCTET STRING value and copies its contents into the specified output stream. |
String |
decodePrintableString()
Decodes an ASN.1 PrintableString value from the underlying input stream and return it as a String object. |
StringBuffer |
decodePrintableString(StringBuffer buf)
Decodes an ASN.1 PrintableString value from the underlying input stream and appends it to the specified StringBuffer. |
int |
decodeSequence()
Starts the decoding of a BER encoded SEQUENCE. |
int |
decodeSequenceOf()
Starts the decoding of a BER encoded SEQUENCE OF. |
int |
decodeSet()
Starts the decoding of a BER encoded SET. |
int |
decodeSetOf()
Starts the decoding of a BER encoded SET OF. |
void |
decodeString(int tag,
OutputStream out)
Decodes the next ASN.1 character string value and appends its contents bytes to the specified output stream. |
String |
decodeTeletexString()
Decodes an ASN.1 TeletexString value from the underlying input stream and return it as a String object. |
StringBuffer |
decodeTeletexString(StringBuffer buf)
Decodes an ASN.1 TeletexString value from the underlying input stream and appends it to the specified StringBuffer. |
Calendar |
decodeUTCTime()
Decodes an ASN.1 UTCTime value from the underlying input stream and return it as a Date object. |
String |
decodeUTF8String()
Decodes an ASN.1 UTF8String value from the underlying input stream and return it as a String object. |
StringBuffer |
decodeUTF8String(StringBuffer buf)
Decodes an ASN.1 UTF8String value from the underlying input stream and appends it to the specified StringBuffer. |
String |
decodeVisibleString()
Decodes an ASN.1 VisibleString value from the underlying input stream and return it as a String object. |
StringBuffer |
decodeVisibleString(StringBuffer buf)
Decodes an ASN.1 VisibleString value from the underlying input stream and appends it to the specified StringBuffer. |
boolean |
endOf(int id)
Indicates wether the decoding of the constructed value identified by id is finished. |
boolean |
isNextConstructed()
Indicates wether the next ASN.1 value has a constructed encoding. |
boolean |
isNextTag(int tag)
Checks if the tag of the next decoded value is equals to the specified tag value. |
void |
skipNext()
Skips the next encoded ASN.1 value. |
| Method Detail |
public void decodeAny(OutputStream out)
throws IOException
out - the output stream the decoded ANY value are copied into.
NullPointerException - if the given output stream is null.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded value.
public byte[] decodeAny()
throws IOException
IOException
public boolean decodeBoolean()
throws IOException
boolean value.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded BOOLEAN value.
public BigInteger decodeInteger()
throws IOException
BigInteger value.
The less expensive decodeIntegerAsInt and decodeIntegerAsLong methods
should be preferred if there is some restriction on the range of the
decoded ASN.1 INTEGER value.
BigInteger representing the content of decoded
ASN.1 INTEGER value.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded INTEGER value.decodeIntegerAsInt(),
decodeIntegerAsLong()
public int decodeIntegerAsInt()
throws IOException
int value.
The caller must be sure that the decoded INTEGER can be represented in a
4-bytes int, otherwise a DecodingException is
thrown to indicate that an overflow occured.
int value representing the content of decoded
ASN.1 INTEGER value.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded INTEGER value or if the INTEGER value does not fit in a 4-bytes
int.
public long decodeIntegerAsLong()
throws IOException
long value.
The caller must be sure that the decoded INTEGER can be represented in a
8-bytes long, otherwise a DecodingException is
thrown to indicate that an overflow occured.
Note:This method is currently not implemented and always throws a
UnsupportedOperationException when it is invoked.
long value representing the content of decoded
ASN.1 INTEGER value.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded INTEGER value or if the INTEGER value does not fit in a 8-bytes
long.
public BitString decodeBitString()
throws IOException
BitString value. The first bit value of the returned
BitString is equals to the first bit value of the decoded
BIT STRING value, and so on.
The total number of bit contained in the decoded BIT STRING may be
retrieved by invoking the length method of the
returned BitString.
This method is equivalent to decodeBitString(new
BitString());
BitString instance representing the content of the
decoded BIT STRING.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded BIT STRING value.decodeBitString(BitString)
public BitString decodeBitString(BitString set)
throws IOException
BitString. The first bit of
the decode BIT STRING value corresponds to the bit at index
set.length() + 1 of the BitString.
The total number of bit contained in the decoded BIT STRING may be
retrieved by invoking the length method of the
returned BitString.
set - the BitString to which the decoded bits are appended.
BitString instance representing the content of the
decoded BIT STRING.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded BIT STRING value.
public byte[] decodeOctetString()
throws IOException
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded OCTET STRING value.
public void decodeOctetString(OutputStream buf)
throws IOException
buf - the output stream receiving the decoded octets.
NullPointerException - if the given output stream is null.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded OCTET STRING value.
public void decodeNull()
throws IOException
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded NULL value.
public BigInteger decodeEnumerated()
throws IOException
BigInteger value.
The less expensive decodeEnumeratedAsInt and decodeEnumeratedAsLong
methods should be preferred if there is some restriction on the range of
the decoded ASN.1 ENUMERATED value, which is the common case if no
extension has been used in the type specification.
BigInteger representing the content of decoded
ASN.1 ENUMERATED value.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded INTEGER value.decodeEnumeratedAsInt(),
decodeEnumeratedAsLong()
public int decodeEnumeratedAsInt()
throws IOException
int value.
The caller must be sure that the decoded ENUMERATED can be represented in
a 4-bytes int, otherwise a DecodingException is
thrown to indicate that an overflow occured.
int value representing the content of decoded
ASN.1 ENUMERATED value.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded ENUMERATED value or if the ENUMERATED value does not fit in a
4-bytes int.
public long decodeEnumeratedAsLong()
throws IOException
int value.
The caller must be sure that the decoded ENUMERATED can be represented in
a 8-bytes int, otherwise a DecodingException is
thrown to indicate that an overflow occured.
int value representing the content of decoded
ASN.1 ENUMERATED value.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded ENUMERATED value or if the ENUMERATED value does not fit in a
8-bytes int.
public ObjectIdentifier decodeObjectIdentifier()
throws IOException
ObjectIdentifier.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded ObjectIdentifier value.
public String decodeUTF8String()
throws IOException
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded UTF8String value.
public StringBuffer decodeUTF8String(StringBuffer buf)
throws IOException
StringBuffer.
buf - the buffer the decoded string is appended to.
StringBuffer the decoded UTF8String is
appended to.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded UTF8String value.
public String decodeNumericString()
throws IOException
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded NumericString value.
public StringBuffer decodeNumericString(StringBuffer buf)
throws IOException
StringBuffer.
buf - the buffer the decoded string is appended to.
StringBuffer the decoded UTF8String is
appended to.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded NumericString value.
public String decodeIA5String()
throws IOException
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded IA5String value.
public StringBuffer decodeIA5String(StringBuffer buf)
throws IOException
StringBuffer.
buf - the buffer the decoded string is appended to.
StringBuffer the decoded UTF8String is
appended to.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded IA5String value.
public String decodePrintableString()
throws IOException
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded PrintableString value.
public StringBuffer decodePrintableString(StringBuffer buf)
throws IOException
StringBuffer.
buf - the buffer the decoded string is appended to.
StringBuffer the decoded PrintableString
is appended to.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded PrintableString value.
public String decodeTeletexString()
throws IOException
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded TeletexString value.
public StringBuffer decodeTeletexString(StringBuffer buf)
throws IOException
StringBuffer.
buf - the buffer the decoded string is appended to.
StringBuffer the decoded TeletexString is
appended to.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded TeletexString value.
public String decodeVisibleString()
throws IOException
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded VisibleString value.
public StringBuffer decodeVisibleString(StringBuffer buf)
throws IOException
StringBuffer.
buf - the buffer the decoded string is appended to.
StringBuffer the decoded UTF8String is
appended to.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded VisibleString value.
public String decodeBMPString()
throws IOException
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded VisibleString value.
public StringBuffer decodeBMPString(StringBuffer buf)
throws IOException
StringBuffer. The
appended StringBuffer is then returned.
buf - the StringBuffer the decoded string is appended to.
StringBuffer the decoded BMPString is
appended to.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded BMPString value.
public void decodeString(int tag,
OutputStream out)
throws IOException
tag - the expected tag of the decoded ASN.1 string value.out - the output stream to which the contents bytes are to be
appended.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded character string value.
public Calendar decodeUTCTime()
throws IOException
Date object.
Date instance representing the decoded UTCTime.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded UTCTime value.
public Calendar decodeGeneralizedTime()
throws IOException
Calendar object.
Calendar instance representing the decoded
GeneralizedTime.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded GeneralizedTime value.
public int decodeChoice()
throws IOException
Type ::= CHOICE { INTEGER i, VisibleString s}
must be decoded as follows
switch (dec.decodeChoice()) {
case Tags.INTEGER:
i = dec.decodeInteger();
break;
case Tags.VISIBLESTRING:
s = decodeVisibleString();
}
IOException - if an I/O error occurs.
DecodingException - if the decoder could not recognize a choice
value.
public int decodeSequence()
throws IOException
decode methods. Finally, the endOf method must be invoked to terminate the decoding of the SEQUENCE.
The returned int value must be passed to the endOf method
that then checks if the current nesting and the passed int do match.
The code samples below show the decoding of two nested sequences. The
corresponding ASN.1 definition is:
SEQUENCE {
s IA5String,
a SEQUENCE {
i INTEGER
}
}
int id1 = dec.decodeSequence();
String s = dec.decodeIA5String();
int id2 = dec.decodeSequence();
BigInteger i = dec.decodeInteger();
dec.endOf(id2);
dec.endOf(id1);
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded SEQUENCE.
public int decodeSequenceOf()
throws IOException
decode methods. Finally, the endOf method must be invoked to terminate the decoding of the
SEQUENCE OF.
The returned int value must be passed to the endOf method
that then checks if the current nesting and the passed int do match.
The code samples below show the decoding of a SEQUENCE OF type. The
corresponding ASN.1 definition is:
MyList ::= SEQUENCE OF PrintableStringand the decoding looks like:
List seq = ...
int id = dec.decodeSequenceOf();
while (!dec.endOf(id)) {
String s = dec.decodePrintableString();
// do something with the elements
seq.add(s);
}
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded SEQUENCE OF.
public int decodeSet()
throws IOException
decode methods. Finally, the endOf method
must be invoked to terminate the decoding of the SET.
The returned int value must be passed to the endOf method
that then checks if the current nesting and the passed int do match.
The code samples below show the decoding of a SET type. The corresponding
ASN.1 definition is:
MySet ::= SET {
s [0] IA5String,
a [1] BOOLEAN
and the decoding looks like:
int id1 = dec.decodeSetOf();
while (!dec.endOf(id1)) {
if (dec.isNextTag(Tags.createTag(Tags.CONTEXT, 0))) {
int ctx = dec.decodeExplicit(Tags.createTag(Tags.CONTEXT, 0));
String s = dec.decodeIA5String();
dec.decodeEndOf(ctx);
} else if (dec.isNextTag(Tags.createTag(Tags.CONTEXT, 1))) {
int ctx = dec.decodeExplicit(Tags.createTag(Tags.CONTEXT, 1));
boolean b = dec.decodeBoolean();
dec.decodeEndOf(ctx);
} else {
// throw an exception
}
}
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded SET.
public int decodeSetOf()
throws IOException
decode methods. Finally, the endOf method must be invoked to terminate the decoding of the SET OF.
The returned int value must be passed to the endOf method
that then checks if the current nesting and the passed int do match.
The code samples below show the decoding of a SET OF type. The
corresponding ASN.1 definition is:
MySet ::= SET OF PrintableStringand the decoding looks like:
Set set = ...
int id = dec.decodeSetOf();
while (!dec.endOf(id)) {
String s = dec.decodePrintableString();
// do something with the elements
set.add(s);
}
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded SET OF.
public boolean endOf(int id)
throws IOException
id is finished. The decoding of a constructed value is
initiated by invoking one of the following methods: decodeSequence() decodeSequenceOf() decodeSet()
decodeSetOf() decodeExplicit(int) decodeConstructed(int)
id - the reference to a constructed value. It must be the value
returned by the method that initiated the decoding of the referenced
constructed value.
true if the decoding of the the constructed value
referenced by false
otherwise.
DecodingException - if the id doesn't reference any
constructed value, or if the referenced constructed value has been
already decoded.
IOException - if an I/O error occurs.
public void decodeEndOf(int id)
throws IOException
id is finished. The decoder checks that the end of the
referenced constructed value has been reached and throws a
DecodingException if the constructed value contains some
more embedded values.
id - the reference to a constructed value.
IOException - if an I/O error occurs.
public void skipNext()
throws IOException
IOException - if an I/O error occurs.
public int decodeExplicit(int tag)
throws IOException
endOf method must be invoked to terminate the
explicitly decoding.
The decoding of the following ASN.1 type
version [0] EXPLICIT Versionlooks like:
int id = dec.decodeExplicit(Tags.makeTag(Tags.CONTEXT, 0)); BigInteger version = dec.decodeInteger(); dec.endOf(id);
tag - the explicit tag of the next decoded ASN.1 value. The tag must
be a valid tag such as one that has been created with the Tags.createTag(int, int) method.
IOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded ObjectIdentifier value.endOf(int),
Tags.createTag(int, int)
public void decodeImplicit(int tag)
throws IOException
dec.decodeImplicit(Tags.makeTag(Tags.CONTEXT, 5)); ... dec.decodeImplicit(Tags.makeTag(Tags.CONTEXT, 7)); BigInteger i = dec.decodeInteger();are equivalent to
dec.decodeImplicit(Tags.makeTag(Tags.CONTEXT, 5)); BigInteger i = dec.decodeInteger();This tag reduction mechanism is useful for decoding ASN.1 type like
Type1 ::= [APPLICATION 2] IMPLICIT INTEGER Type2 ::= [APPLICATION 5] IMPLICIT Type1where the code used to decode value of type Type2 looks like
dec.decodeImplicit(Tags.makeTag(Tags.APPLICATION, 5)); dec.decodeImplicit(Tags.makeTag(Tags.APPLICATION, 2)); dec.decodeInteger();
tag - the implicit tag that is expected for the next decoded value.
IOException - if an I/O error occurs.
public boolean isNextTag(int tag)
throws IOException
SEQUENCE {
a [0] IMPLICIT INTEGER OPTIONAL,
b BOOLEAN
}
may be decoded as follows:
int id = dec.decodeSequence();
if (dec.isNextTag(Tags.createTag(Tags.CONTEXT, 0))) {
dec.decodeImplicit(Tags.createTag(Tags.CONTEXT, 0));
a = dec.decodeInteger();
}
b = dec.decodeBoolean();
dec.decodeEndOf(id);
tag - the expected tag value to check with.
true if the next encoded value has the specified
tag, false otherwise.
IOException - if an I/O error occurs.
public boolean isNextConstructed()
throws IOException
true if the encoding is constructed,
false otherwise.
IOException - if an I/O error occured.
public int decodeConstructed(int tag)
throws IOException
tag.
If the encodeImplicit() method has been previously invoked, its passed
tag parameter is used instead of the specified tag.
This method creates and returns a unique identifier for referencing the
decoded constructed value.
if (dec.isNextConstructed()) {
int id = dec.decodeConstructed(Tags.PRINTABLESTRING);
while (!dec.endOf(id)) {
System.out.println(dec.decodePrintableString());
}
} else {
System.out.println(dec.decodePrintableString());
}
tag - the tag of the constructed value to be decoded.
endOf method to terminate the
decoding.
IOException - if an I/O error occurs.
DecodingException - if the decoded tag value is not equals to the
specified one (or not equals to an implicitely tag value passed by a
previous call to the encodeImplicit() method) or if the value has not a
constructed encoding.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||