com.objsys.asn1j.runtime
Class Asn1PerDecodeBuffer

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.Asn1PerDecodeBuffer
All Implemented Interfaces:
Asn1PerMessageBuffer
Direct Known Subclasses:
Asn1PerInputStream

public class Asn1PerDecodeBuffer
extends Asn1DecodeBuffer
implements Asn1PerMessageBuffer

This class handles the decoding of ASN.1 messages as specified in the Packed Encoding Rules (PER) as specified in the ITU-T X.691 standard.


Field Summary
protected  Asn1PerTraceHandler mTraceHandler
           
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1DecodeBuffer
mByteCount
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
context, mTypeCode
 
Constructor Summary
Asn1PerDecodeBuffer(byte[] msgdata, boolean aligned)
          This constructor creates a PER decode buffer object that references an encoded ASN.1 message.
Asn1PerDecodeBuffer(java.io.InputStream istream, boolean aligned)
          This constructor creates a PER decode buffer object that references an encoded ASN.1 message.
 
Method Summary
 void binDump(java.io.PrintStream out, java.lang.String varName)
          This method dumps the encoded message in a human-readable format showing a bit trace of all fields to the given print output stream.
 void binDump(java.lang.String varName)
          This method invokes an overloaded version of binDump to dump the encoded message to standard output.
 void byteAlign()
          This methods byte-aligns the buffer.
 boolean decodeBit()
          This method decodes a single bit value.
 boolean decodeBit(java.lang.String ident)
          This method decodes a single bit value.
 int decodeBitsToInt(int nbits)
          This method decodes bits from the input stream into a standard integer value.
 int decodeBitsToInt(int nbits, java.lang.String ident)
          This method decodes bits from the input stream into a standard integer value.
 long decodeBitsToLong(int nbits)
          This method decodes bits from the input stream into a long integer value.
 long decodeBitsToLong(int nbits, java.lang.String ident)
          This method decodes bits from the input stream into a long integer value.
 void decodeBitsToOctetArray(byte[] value, int offset, int nbits)
          This method decodes bits from the input stream into an array of octets.
 void decodeBitsToOctetArray(byte[] value, int offset, int bitOffset, int nbits, java.lang.String ident)
          This method decodes bits from the input stream into an array of octets.
 void decodeBitsToOctetArray(byte[] value, int offset, int nbits, java.lang.String ident)
          This method decodes bits from the input stream into an array of octets.
 void decodeCharString(int nchars, int abpc, int ubpc, Asn1CharSet charSet, java.lang.StringBuffer sbuf)
          This method decodes the contents of a known-multiplier character string.
 long decodeConsWholeNumber(long rangeValue)
          This method implements the rules to decode a constrained whole number as specified in section 10.5 of the X.691 standard.
 long decodeConsWholeNumber(long rangeValue, java.lang.String ident)
          This method implements the rules to decode a constrained whole number as specified in section 10.5 of the X.691 standard.
 long decodeExtLength()
          This method decodes an extension length value.
 long decodeInt(int nocts, boolean signExtend)
          This method implements the rules to decode an unconstrained integer value.
 long decodeInt(int nocts, boolean signExtend, java.lang.String ident)
          This method implements the rules to decode an unconstrained integer value.
 long decodeLength()
          This method decodes a general (unconstrained) length determinant value as described in section 10.9 of the X.691 standard.
 long decodeLength(long lower, long upper)
          This method decodes a constrained length determinant value.
 int decodeSmallLength()
          This method implements the rules to decode a normally small length as specified in section 11.9 of the X.691 standard.
 int decodeSmallNonNegWholeNumber()
          This method implements the rules to decode a small non-negative whole number as specified in section 10.6 of the X.691 standard.
 long getBitOffset()
          This method returns the absolute offset to the current bit in the decode buffer.
 int getMsgBitCnt()
          This method returns the number of bits in the encoded PER message.
 Asn1PerTraceHandler getTraceHandler()
          This method will return a reference to the internal trace handler object used to trace the bit fields within a PER message.
 boolean isAligned()
          This method tests if PER alignment is turned on or off.
 void moveBitCursor(long offset)
          This method moves the bit cursor to the given offset.
 int readByte()
          This method returns the next available 8-bit value from the input stream.
 void setAligned(boolean value)
          This method is used to turn PER aligned encoding on or off.
static Asn1PerDecodeBuffer setBuffer(Asn1PerDecodeBuffer buffer, byte[] msgdata, boolean aligned)
          This method will create or reinitialize a PER decode message buffer object to read data from the given byte array.
 void setInputStream(byte[] msgdata, int offset, int length)
          This method will set the input stream from which data is read.
 
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, 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
 
Methods inherited from interface com.objsys.asn1j.runtime.Asn1PerMessageBuffer
getInputStream
 

Field Detail

mTraceHandler

protected Asn1PerTraceHandler mTraceHandler
Constructor Detail

Asn1PerDecodeBuffer

public Asn1PerDecodeBuffer(byte[] msgdata,
                           boolean aligned)
This constructor creates a PER decode buffer object that references an encoded ASN.1 message.

Parameters:
msgdata - Byte array containing an encoded ASN.1 message.
aligned - Boolean specifying PER aligned or unaligned encoding.

Asn1PerDecodeBuffer

public Asn1PerDecodeBuffer(java.io.InputStream istream,
                           boolean aligned)
This constructor creates a PER 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.
aligned - Boolean specifying PER aligned or unaligned encoding.
Method Detail

binDump

public void binDump(java.lang.String varName)
This method invokes an overloaded version of binDump to dump the encoded message to standard output.

Parameters:
varName - Name of top-level message object variable

binDump

public void binDump(java.io.PrintStream out,
                    java.lang.String varName)
This method dumps the encoded message in a human-readable format showing a bit trace of all fields to the given print output stream.

Parameters:
out - PrintStream object to which output should be written
varName - Name of top-level message object variable

byteAlign

public void byteAlign()
This methods byte-aligns the buffer.

Specified by:
byteAlign in interface Asn1PerMessageBuffer

decodeBit

public boolean decodeBit(java.lang.String ident)
                  throws Asn1EndOfBufferException,
                         java.io.IOException
This method decodes a single bit value.

Parameters:
ident - Bit field identifier name for tracing.
Returns:
Boolean value of bit that was decoded.
Throws:
Asn1EndOfBufferException
java.io.IOException

decodeBit

public boolean decodeBit()
                  throws Asn1EndOfBufferException,
                         java.io.IOException
This method decodes a single bit value. The ident argument which is used for tracing is defaulted to 'value'.

Returns:
Boolean value of bit that was decoded.
Throws:
Asn1EndOfBufferException
java.io.IOException

decodeBitsToLong

public long decodeBitsToLong(int nbits,
                             java.lang.String ident)
                      throws Asn1Exception,
                             java.io.IOException
This method decodes bits from the input stream into a long integer value. Up to 64 bits can be decoded. The bits are placed in the least-significant bytes of the long integer.

Parameters:
nbits - Number of bits to decode
ident - Bit field identifier name for tracing.
Returns:
Long integer value containing decoded bits
Throws:
Asn1Exception
java.io.IOException

decodeBitsToLong

public long decodeBitsToLong(int nbits)
                      throws Asn1Exception,
                             java.io.IOException
This method decodes bits from the input stream into a long integer value. Up to 64 bits can be decoded. The bits are placed in the least-significant bytes of the long integer. The ident argument which is used for tracing is defaulted to 'value'.

Parameters:
nbits - Number of bits to decode
Returns:
Long integer value containing decoded bits
Throws:
Asn1Exception
java.io.IOException

decodeBitsToInt

public int decodeBitsToInt(int nbits,
                           java.lang.String ident)
                    throws Asn1Exception,
                           java.io.IOException
This method decodes bits from the input stream into a standard integer value. Up to 32 bits can be decoded. The bits are placed in the least-significant bytes of the integer.

Parameters:
nbits - Number of bits to decode
ident - Bit field identifier name for tracing.
Returns:
Integer value containing decoded bits
Throws:
Asn1Exception
java.io.IOException

decodeBitsToInt

public int decodeBitsToInt(int nbits)
                    throws Asn1Exception,
                           java.io.IOException
This method decodes bits from the input stream into a standard integer value. Up to 32 bits can be decoded. The bits are placed in the least-significant bytes of the integer. The ident argument which is used for tracing is defaulted to 'value'.

Parameters:
nbits - Number of bits to decode
Returns:
Integer value containing decoded bits
Throws:
Asn1Exception
java.io.IOException

decodeBitsToOctetArray

public void decodeBitsToOctetArray(byte[] value,
                                   int offset,
                                   int nbits,
                                   java.lang.String ident)
                            throws Asn1Exception,
                                   java.io.IOException
This method decodes bits from the input stream into an array of octets. The user is expected to have provided an array large enough to hold the number of bits requested to be decoded.

Parameters:
value - Octet array for decoded data
offset - Starting byte offset into array
nbits - Number of bits to decode
ident - Bit field identifier name for tracing, or null.
Throws:
Asn1Exception
java.io.IOException

decodeBitsToOctetArray

public void decodeBitsToOctetArray(byte[] value,
                                   int offset,
                                   int bitOffset,
                                   int nbits,
                                   java.lang.String ident)
                            throws Asn1Exception,
                                   java.io.IOException
This method decodes bits from the input stream into an array of octets. The user is expected to have provided an array large enough to hold the number of bits requested to be decoded. The first bit is decoded into the given offset byte at the MSB if bitOffset == 0, and at the LSB if bitOffset == 7.

Parameters:
value - Octet array for decoded data
offset - Starting byte offset into array
bitOffset - Where in first byte the first bit goes
nbits - Number of bits to decode
ident - Bit field identifier name for tracing, or null.
Throws:
Asn1Exception
java.io.IOException

decodeBitsToOctetArray

public void decodeBitsToOctetArray(byte[] value,
                                   int offset,
                                   int nbits)
                            throws Asn1Exception,
                                   java.io.IOException
This method decodes bits from the input stream into an array of octets. The user is expected to have provided an array large enough to hold the number of bits requested to be decoded. The ident argument which is used for tracing is defaulted to 'value'.

Parameters:
value - Octet array for decoded data
offset - Starting byte offset into array
nbits - Number of bits to decode
Throws:
Asn1Exception
java.io.IOException

decodeCharString

public void decodeCharString(int nchars,
                             int abpc,
                             int ubpc,
                             Asn1CharSet charSet,
                             java.lang.StringBuffer sbuf)
                      throws Asn1Exception,
                             java.io.IOException
This method decodes the contents of a known-multiplier character string. This version of the method assumes a permitted alphabet constraint is in place.

Parameters:
nchars - Number of characters
abpc - Number of bits per character (aligned)
ubpc - Number of bits per character (unaligned)
charSet - Object representing the permitted alphabet constraint character set (optional)
sbuf - String buffer to receive decoded result
Throws:
Asn1Exception
java.io.IOException

decodeConsWholeNumber

public long decodeConsWholeNumber(long rangeValue,
                                  java.lang.String ident)
                           throws Asn1Exception,
                                  java.io.IOException
This method implements the rules to decode a constrained whole number as specified in section 10.5 of the X.691 standard.

Parameters:
rangeValue - upper - lower + 1. If a negative value is passed, it will be interpreted as an unsigned integer. If 0 is given, it will be interpreted as 2^64.
ident - Tracing identifier
Returns:
Decoded adjusted value = value - lower range endpoint value.
Throws:
Asn1Exception
java.io.IOException

decodeConsWholeNumber

public long decodeConsWholeNumber(long rangeValue)
                           throws Asn1Exception,
                                  java.io.IOException
This method implements the rules to decode a constrained whole number as specified in section 10.5 of the X.691 standard. The ident argument which is used for tracing is defaulted to 'value'.

Parameters:
rangeValue - upper - lower + 1. If a negative value is passed, it will be interpreted as an unsigned integer. If 0 is given, it will be interpreted as 2^64.
Returns:
Decoded adjusted value = value - lower range endpoint value
Throws:
Asn1Exception
java.io.IOException

decodeExtLength

public long decodeExtLength()
                     throws Asn1Exception,
                            java.io.IOException
This method decodes an extension length value. Note that the decoded length is not what is returned. The bit offset to the start of the next element within the decode buffer is returned.

Returns:
Bit offset to next element in buffer
Throws:
Asn1Exception
java.io.IOException

decodeInt

public long decodeInt(int nocts,
                      boolean signExtend,
                      java.lang.String ident)
               throws Asn1Exception,
                      java.io.IOException
This method implements the rules to decode an unconstrained integer value.

Parameters:
nocts - Number of octets to decode
signExtend - Sign extend resulting value?
ident - Tracing identifier
Returns:
Decoded long integer value
Throws:
Asn1Exception
java.io.IOException

decodeInt

public long decodeInt(int nocts,
                      boolean signExtend)
               throws Asn1Exception,
                      java.io.IOException
This method implements the rules to decode an unconstrained integer value. The ident argument which is used for tracing is defaulted to 'value'.

Parameters:
nocts - Number of octets to decode
signExtend - Sign extend resulting value?
Returns:
Decoded long integer value
Throws:
Asn1Exception
java.io.IOException

decodeLength

public long decodeLength()
                  throws Asn1Exception,
                         java.io.IOException
This method decodes a general (unconstrained) length determinant value as described in section 10.9 of the X.691 standard. The maximum value that will be returned is 64K which is the largest length fragment size defined for PER. If a value of 16K or larger is returned, the user must repeat this call to fully decode the fragmented contents.

Returns:
Decoded length value. If the returned value is >= 16k, this indicates a fragmented length was decoded. The user must call this method again after the data fragment is decoded to get the next fragment length.
Throws:
Asn1Exception
java.io.IOException

decodeLength

public long decodeLength(long lower,
                         long upper)
                  throws Asn1Exception,
                         java.io.IOException
This method decodes a constrained length determinant value. If upper >= 64K, it is possible that the data has been fragmented. If this is the case and this method returns >= 16K, then there will be another length encoded following the current chunk.

Parameters:
lower - Lower bound (inclusive) of length value range
upper - Upper bound (inclusive) of length value range
Returns:
Decoded length value
Throws:
Asn1Exception
java.io.IOException

decodeSmallLength

public int decodeSmallLength()
                      throws Asn1Exception,
                             java.io.IOException
This method implements the rules to decode a normally small length as specified in section 11.9 of the X.691 standard.

Throws:
Asn1Exception
java.io.IOException

decodeSmallNonNegWholeNumber

public int decodeSmallNonNegWholeNumber()
                                 throws Asn1Exception,
                                        java.io.IOException
This method implements the rules to decode a small non-negative whole number as specified in section 10.6 of the X.691 standard.

Throws:
Asn1Exception
java.io.IOException

getBitOffset

public long getBitOffset()
This method returns the absolute offset to the current bit in the decode buffer.

Returns:
Offset to current bit in decode buffer

getMsgBitCnt

public int getMsgBitCnt()
This method returns the number of bits in the encoded PER message.

Specified by:
getMsgBitCnt in interface Asn1PerMessageBuffer
Returns:
Count of bits in encoded message

isAligned

public boolean isAligned()
This method tests if PER alignment is turned on or off.

Specified by:
isAligned in interface Asn1PerMessageBuffer

moveBitCursor

public void moveBitCursor(long offset)
                   throws Asn1EndOfBufferException,
                          java.io.IOException
This method moves the bit cursor to the given offset.

Parameters:
offset - Absolute bit offset value
Throws:
Asn1EndOfBufferException
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

setAligned

public void setAligned(boolean value)
This method is used to turn PER aligned encoding on or off.

Parameters:
value - Boolean specifying PER aligned (true) or unaligned encoding (false).

setBuffer

public static Asn1PerDecodeBuffer setBuffer(Asn1PerDecodeBuffer buffer,
                                            byte[] msgdata,
                                            boolean aligned)
This method will create or reinitialize a PER decode message buffer object to read data from the given byte array. If the existing buffer reference is null, a new buffer will be created; otherwise, the existing buffer will be reused.

Parameters:
buffer - Existing message buffer object
msgdata - Byte array containing message data
aligned - Boolean specifying PER aligned or unaligned encoding.

setInputStream

public void setInputStream(byte[] msgdata,
                           int offset,
                           int length)
This method will set the input stream from which data is read. This version of the method allows a byte array containing encoded data to be specified.

Overrides:
setInputStream in class Asn1DecodeBuffer
Parameters:
msgdata - Byte array containing encoded message data
offset - Starting offset of data in the byte array
length - Length (in bytes) of the encoded data

getTraceHandler

public Asn1PerTraceHandler getTraceHandler()
This method will return a reference to the internal trace handler object used to trace the bit fields within a PER message.

Specified by:
getTraceHandler in interface Asn1PerMessageBuffer