|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jasn.BerDecoder
A decoder for parsing BER encoded ASN.1 values from an input stream.
| Constructor Summary | |
BerDecoder(InputStream in)
Creates a decoder for parsing BER encoded ASN.1 values from the specified input stream. |
|
BerDecoder(InputStream in,
int bufSize)
Creates a decoder for parsing BER encoded ASN.1 values from the specified input stream. |
|
| Method Summary | |
byte[] |
decodeAny()
|
void |
decodeAny(OutputStream out)
Decodes an ASN.1 ANY value from the underlying stream 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. |
protected void |
matchTag(int tag,
boolean constructed)
Decodes a BER encoded tag and checks that its value matches the specified value and that is is constructed if constructed
is true. |
void |
setInputStream(InputStream in)
Sets the underlying input stream from which the ASN.1 values are decoded. |
void |
skipNext()
Skips the next encoded ASN.1 value. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public BerDecoder(InputStream in,
int bufSize)
in - the underlying input stream.bufSize - the size of the internal buffer used for decoding.
NullPointerException - if the given input stream is null.public BerDecoder(InputStream in)
1024 is used.
in - the underlying input stream.| Method Detail |
public void setInputStream(InputStream in)
in - the new input stream to parse from.
public void decodeAny(OutputStream out)
throws IOException
Note: The complete ASN.1 encoding (including tag, length and content's bytes) are copied into the stream.
decodeAny in interface Asn1Decoderout - 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
decodeAny in interface Asn1DecoderIOException
public boolean decodeBoolean()
throws IOException
boolean value.
decodeBoolean in interface Asn1DecoderIOException - 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.
decodeInteger in interface Asn1DecoderBigInteger 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.
decodeIntegerAsInt in interface Asn1Decoderint 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.
decodeIntegerAsLong in interface Asn1Decoderlong 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());
decodeBitString in interface Asn1DecoderBitString 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.
decodeBitString in interface Asn1Decoderset - 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
decodeOctetString in interface Asn1DecoderIOException - 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
decodeOctetString in interface Asn1Decoderbuf - 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
decodeNull in interface Asn1DecoderIOException - 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.
decodeEnumerated in interface Asn1DecoderBigInteger 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.
decodeEnumeratedAsInt in interface Asn1Decoderint 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.
decodeEnumeratedAsLong in interface Asn1Decoderint 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
decodeObjectIdentifier in interface Asn1DecoderObjectIdentifier.
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
decodeUTF8String in interface Asn1DecoderIOException - 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.
decodeUTF8String in interface Asn1Decoderbuf - 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
decodeNumericString in interface Asn1DecoderIOException - 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.
decodeNumericString in interface Asn1Decoderbuf - 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
decodeIA5String in interface Asn1DecoderIOException - 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.
decodeIA5String in interface Asn1Decoderbuf - 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
decodePrintableString in interface Asn1DecoderIOException - 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.
decodePrintableString in interface Asn1Decoderbuf - 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
decodeTeletexString in interface Asn1DecoderIOException - 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.
decodeTeletexString in interface Asn1Decoderbuf - 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
decodeVisibleString in interface Asn1DecoderIOException - 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.
decodeVisibleString in interface Asn1Decoderbuf - 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
decodeBMPString in interface Asn1DecoderIOException - 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.
decodeBMPString in interface Asn1Decoderbuf - 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
decodeString in interface Asn1Decodertag - 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.
decodeUTCTime in interface Asn1DecoderDate 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.
decodeGeneralizedTime in interface Asn1DecoderCalendar 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
For example, the value of the CHOICE type
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();
}
decodeChoice in interface Asn1DecoderIOException - if an I/O error occurs.
DecodingException - if the decoder could not recognize a choice
value.
public int decodeSequence()
throws IOException
An ASN.1 SEQUENCE is an ordered collection of various data element.
The decoding of a SEQUENCE must always start with this method;
then the elements defined in the SEQUENCE should be decoded with their
corresponding 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);
decodeSequence in interface Asn1DecoderIOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded SEQUENCE.
public int decodeSequenceOf()
throws IOException
An ASN.1 SEQUENCE OF is an ordered collection of data elements of the
same type.
The decoding of a SEQUENCE OF must always start with this method;
then the elements defined in the SEQUENCE OF should be decoded with their
corresponding 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);
}
decodeSequenceOf in interface Asn1DecoderIOException - 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
An ASN.1 SET is an unordered collection of various data elements.
The decoding of a SET must always start with this method;
then the elements defined in the SET should be decoded with their
corresponding 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
}
}
decodeSet in interface Asn1DecoderIOException - if an I/O error occurs.
DecodingException - if the bytes read do not represent a valid BER
encoded SET.
public int decodeSetOf()
throws IOException
An ASN.1 SET OF is an unordered collection of data elements of the
same type.
The decoding of a SET OF must always start with this method;
then the elements defined in the SET OF should be decoded with their
corresponding 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);
}
decodeSetOf in interface Asn1DecoderIOException - 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)
endOf in interface Asn1Decoderid - 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.
decodeEndOf in interface Asn1Decoderid - the reference to a constructed value.
IOException - if an I/O error occurs.
public void skipNext()
throws IOException
skipNext in interface Asn1DecoderIOException - if an I/O error occurs.
public int decodeExplicit(int tag)
throws IOException
Explicit tags create a separate (tag, length, value) tripplet where the
tagged element is encoded as value.
This method must be called
before the ASN.1 value is decoded; then the value itself is handled as
usual. Finally, the 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);
decodeExplicit in interface Asn1Decodertag - 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
This method may be invoked many time with different implicit tags before invoking the subsequent decoding method, but only the first decodeImplicit method has an effect and all the other tags will be ignored. In other words, the following statements
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();
decodeImplicit in interface Asn1Decodertag - 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);
isNextTag in interface Asn1Decodertag - 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
isNextConstructed in interface Asn1Decodertrue if the encoding is constructed,
false otherwise.
IOException - if an I/O error occured.
public int decodeConstructed(int tag)
throws IOException
This method decodes a tag value from the stream and verifies that
it is constructed and that it's value is equals to 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());
}
decodeConstructed in interface Asn1Decodertag - 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.
protected void matchTag(int tag,
boolean constructed)
throws IOException
constructed
is true.
tag - the tag value of the decoded tag. It must be a value created
with the Tag.makeTag() method.constructed - indicates wether the decoded tag must be constructed
or not.
DecodingException - if the decoded tag has a value that differs
from the specified one or if its constructed flag does not match the
specified one.
IOException - if an I/O error occurs.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||