com.objsys.asn1j.runtime
Class Asn1BerDecodeBuffer

java.lang.Object
  extended by com.objsys.asn1j.runtime.Asn1MessageBufferBase
      extended by com.objsys.asn1j.runtime.Asn1MessageBuffer
          extended by com.objsys.asn1j.runtime.Asn1DecodeBuffer
              extended by com.objsys.asn1j.runtime.Asn1BerDecodeBuffer
Direct Known Subclasses:
Asn1BerInputStream, Asn1DerDecodeBuffer

public class Asn1BerDecodeBuffer
extends Asn1DecodeBuffer

This class handles the decoding of ASN.1 messages as specified in the Basic Encoding Rules (BER) as documented in the ITU-T X.690 standard.


Field Summary
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1DecodeBuffer
mByteCount
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
context, mTypeCode
 
Constructor Summary
Asn1BerDecodeBuffer(byte[] msgdata)
          This constructor creates a BER decode buffer object that references an encoded ASN.1 message.
Asn1BerDecodeBuffer(java.io.InputStream istream)
          This constructor creates a BER decode buffer object that references an encoded ASN.1 message.
 
Method Summary
static int calcIndefLen(byte[] data, int offset, int len)
          This function calculates the actual length of an indefinite length message component.
 int decodeEnumValue(Asn1Tag tag, boolean explicit, int implicitLength)
          This method decodes an enumerated value from the buffer.
 int decodeEnumValue(boolean explicit, int implicitLength)
          This method decodes an enumerated value from the buffer.
 int decodeLength()
          This method decodes a length value.
 byte[] decodeOpenType()
          This method decodes an ASN.1 BER open type value.
 byte[] decodeOpenType(boolean saveData)
          This method decodes an ASN.1 BER open type value.
 void decodeTag(Asn1Tag tag)
          This method decodes a tag value.
 int decodeTagAndLength(Asn1Tag tag)
          This method decodes a tag and length value.
 Asn1Tag getLastTag()
          This method will return the last tag parsed within this decode buffer object.
 boolean matchTag(Asn1Tag tag)
          This overloaded version of matchTag will just test for a match and not return parsed tag and length values
 boolean matchTag(Asn1Tag tag, Asn1Tag parsedTag, IntHolder parsedLen)
          This overloaded version of matchTag allows the tag value to be matched to be passed using an Asn1Tag object.
 boolean matchTag(short tagClass, short tagForm, int tagIDCode, Asn1Tag parsedTag, IntHolder parsedLen)
          This method decodes the next tag value and checks for a match with the given tag value.
protected  void movePastEOC(boolean saveData)
           
 void parse(Asn1TaggedEventHandler handler)
          This method parses the complete message and invokes the event handler callback methods as various items are encountered.
 Asn1Tag peekTag()
          This overloaded version of the peekTag method will return a reference to a newly created tag object.
 void peekTag(Asn1Tag parsedTag)
          This method will parse and return the next tag in the decode stream without advancing the decode cursor.
 int readByte()
          This method returns the next available 8-bit value from the input stream.
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1DecodeBuffer
addCaptureBuffer, capture, decodeIntValue, decodeOIDContents, decodeRelOIDContents, getByteCount, getInputStream, getLazyOpenTypeDecode, hexDump, init, mark, read, read, read, read2Bytes, read4Bytes, removeCaptureBuffer, reset, setInputStream, setLazyOpenTypeDecode, skip
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1MessageBuffer
addNamedEventHandler, getEventHandlerListCount, hasEventHandlers, invokeCharacters, invokeEndElement, invokeStartElement, setEventHandlerList
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
getContext, hexDump, hexDump, setKey, setTypeCode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Asn1BerDecodeBuffer

public Asn1BerDecodeBuffer(byte[] msgdata)
This constructor creates a BER decode buffer object that references an encoded ASN.1 message.

Parameters:
msgdata - Byte array containing an encoded ASN.1 message.

Asn1BerDecodeBuffer

public Asn1BerDecodeBuffer(java.io.InputStream istream)
This constructor creates a BER decode buffer object that references an encoded ASN.1 message. In this case, the message is passed in using an InputStream object.

Parameters:
istream - Input stream containing an encoded ASN.1 message.
Method Detail

calcIndefLen

public static int calcIndefLen(byte[] data,
                               int offset,
                               int len)
                        throws Asn1Exception,
                               java.io.IOException
This function calculates the actual length of an indefinite length message component.

Parameters:
data - Buffer with the indefinite length message component.
offset - Offset in the buffer
len - Length of the buffer (begining from the offset)
Returns:
calculated length
Throws:
Asn1Exception
java.io.IOException

decodeLength

public final int decodeLength()
                       throws Asn1Exception,
                              java.io.IOException
This method decodes a length value.

Returns:
Decoded length value
Throws:
Asn1Exception
java.io.IOException

decodeOpenType

public byte[] decodeOpenType()
                      throws Asn1Exception,
                             java.io.IOException
This method decodes an ASN.1 BER open type value. This is a fully encoded message component of any type. The component is captured in the decode capture buffer and a reference to a byte array is returned containing the component.

Returns:
Reference to byte array containing component.
Throws:
Asn1Exception
java.io.IOException

decodeOpenType

public byte[] decodeOpenType(boolean saveData)
                      throws Asn1Exception,
                             java.io.IOException
This method decodes an ASN.1 BER open type value. This is a fully encoded message component of any type. This version of the method allows the option of saving or discarding the open type data.

Parameters:
saveData - True if data should be captured and returned
Returns:
Reference to byte array containing component.
Throws:
Asn1Exception
java.io.IOException

movePastEOC

protected final void movePastEOC(boolean saveData)
                          throws Asn1Exception,
                                 java.io.IOException
Throws:
Asn1Exception
java.io.IOException

decodeTag

public final void decodeTag(Asn1Tag tag)
                     throws Asn1Exception,
                            java.io.IOException
This method decodes a tag value.

Parameters:
tag - Tag object to receive decoded tag fields.
Throws:
Asn1Exception
java.io.IOException

decodeTagAndLength

public final int decodeTagAndLength(Asn1Tag tag)
                             throws Asn1Exception,
                                    java.io.IOException
This method decodes a tag and length value.

Parameters:
tag - Tag object to receive decoded tag fields.
Returns:
Decoded length value.
Throws:
Asn1Exception
java.io.IOException

getLastTag

public Asn1Tag getLastTag()
This method will return the last tag parsed within this decode buffer object.

Returns:
Last parsed tag object reference

matchTag

public final boolean matchTag(short tagClass,
                              short tagForm,
                              int tagIDCode,
                              Asn1Tag parsedTag,
                              IntHolder parsedLen)
                       throws Asn1Exception,
                              java.io.IOException
This method decodes the next tag value and checks for a match with the given tag value. If the match is successful, the decode cursor will be psoitioned at the contents field; otherwise, it will be reset to point to the start of the tag field.

Parameters:
tagClass - Class value of tag to match
tagForm - Form value of tag to match
tagIDCode - ID code of tag to match
parsedTag - Holder object to receive parsed tag value
parsedLen - Holder object to receive parsed length value
Returns:
True if given tag matches tag at decode cursor
Throws:
Asn1Exception
java.io.IOException

matchTag

public final boolean matchTag(Asn1Tag tag,
                              Asn1Tag parsedTag,
                              IntHolder parsedLen)
                       throws Asn1Exception,
                              java.io.IOException
This overloaded version of matchTag allows the tag value to be matched to be passed using an Asn1Tag object.

Parameters:
tag - Tag value to be matched.
parsedTag - Holder object to receive parsed tag value
parsedLen - Holder object to receive parsed length value
Returns:
True if given tag matches tag at decode cursor
Throws:
Asn1Exception
java.io.IOException

matchTag

public final boolean matchTag(Asn1Tag tag)
                       throws Asn1Exception,
                              java.io.IOException
This overloaded version of matchTag will just test for a match and not return parsed tag and length values

Parameters:
tag - Tag value to be matched.
Returns:
True if given tag matches tag at decode cursor
Throws:
Asn1Exception
java.io.IOException

peekTag

public final void peekTag(Asn1Tag parsedTag)
                   throws Asn1Exception,
                          java.io.IOException
This method will parse and return the next tag in the decode stream without advancing the decode cursor.

Parameters:
parsedTag - Holder object to receive parsed tag value
Throws:
Asn1Exception
java.io.IOException

peekTag

public final Asn1Tag peekTag()
                      throws Asn1Exception,
                             java.io.IOException
This overloaded version of the peekTag method will return a reference to a newly created tag object.

Returns:
Parsed tag object value reference
Throws:
Asn1Exception
java.io.IOException

parse

public void parse(Asn1TaggedEventHandler handler)
           throws Asn1Exception,
                  java.io.IOException
This method parses the complete message and invokes the event handler callback methods as various items are encountered.

Parameters:
handler - Object implementing the Asn1EventHandler interface.
Throws:
Asn1Exception
java.io.IOException

readByte

public int readByte()
             throws Asn1Exception,
                    java.io.IOException
This method returns the next available 8-bit value from the input stream. It is implemented differently for BER/DER and PER to take into account odd alignments in PER.

Specified by:
readByte in class Asn1DecodeBuffer
Returns:
Next 8-bit byte value from input stream
Throws:
Asn1Exception
java.io.IOException

decodeEnumValue

public int decodeEnumValue(boolean explicit,
                           int implicitLength)
                    throws Asn1Exception,
                           java.io.IOException
This method decodes an enumerated value from the buffer. This assumes that the enumerated value is tagged [UNIVERSAL 10].

Parameters:
explicit - Flag that indicates element is explicitly tagged.
implicitLength - Length of contents if implicit.
Returns:
The decoded integer value.
Throws:
Asn1Exception
java.io.IOException

decodeEnumValue

public int decodeEnumValue(Asn1Tag tag,
                           boolean explicit,
                           int implicitLength)
                    throws Asn1Exception,
                           java.io.IOException
This method decodes an enumerated value from the buffer. This method requires an explicit tag to be passed for decoding.

Parameters:
tag - The tag to match for decoding.
explicit - Flag that indicates element is explicitly tagged.
implicitLength - Length of contents if implicit.
Returns:
The decoded integer value.
Throws:
Asn1Exception
java.io.IOException