com.adventnet.snmp.snmp2
Class ASN1Parser

java.lang.Object
  |
  +--com.adventnet.snmp.snmp2.ASN1Parser
All Implemented Interfaces:
java.io.Serializable

public class ASN1Parser
extends java.lang.Object
implements java.io.Serializable

Implements the ASN1Parser that contains the decode and encode methods. You need to instantiate this class to decode/encode an SNMP message.

An instance of the ASN1Parser is instantiated when a SNMP message is created. Each instance of the SNMP message consists of an SnmpPDU and an ASN1Parser. The ASN1Parser keeps track of the state how far a message is decoded.

See Also:
and SnmpPDU, Serialized Form

Method Summary
 int decodeInteger()
          Decodes an ASN.1 Integer Only the least significant 4 bytes are retained
 int decodeLength()
          Decodes an ASN.1 length field of an SNMP packet.
 long[] decodeLong()
          Decodes an ASN.1 Long Only the least significant 8 bytes are retained
 byte[] decodeOctetString()
          Decodes an ASN.1 Octet string.
 int[] decodeOID()
          Decodes an ASN.1 Object Identifier.
 void decodeVarBindList(java.util.Vector variables)
           
 void decrypt(byte[] key, byte[] privParms, int protocol, SecurityModelEntry utils)
          Decrypts the data.
 void encodeCommand(byte command)
          Encodes the command.
 void encodeEnterprise(SnmpOID enterprise)
          Encodes the enterprise.
 void encodeInt(int value)
          Encodes the data type int.
 void encodeIPAddress(SnmpString addr)
          Encodes the IPAddress.
 void encodeOctets(byte[] buf, int length)
          Encodes the octets specified.
 void encodeSequence()
          This method encodes the sequence.
 void encodeSequence(byte type)
          This method encodes the sequence.
 void encodeSequence(int length)
          This method encodes the sequence.
 void encodeSequence(int length, byte type)
          This method encodes the sequence.
 void encodeString(java.lang.String str)
          Encodes the data type string.
 void encodeUInt(int value)
          Encodes the data type unsigned int.
 void encodeVarBindList(java.util.Vector variables)
          Encodes the VarBindList.
 void encrypt(byte[] key, byte[] privParms, int protocol, SecurityModelEntry utils)
          Encrypts the data.
 int getBookMark()
          This method returns the bookmark value.
 byte[] getData()
          Returns the data.
 int getIndex()
          Returns the message index value.
 int getPosition()
          This method returns the position in the buffer where the the data will be encoded/decoded.
 byte[] getReceivedData()
          Returns the data.
 byte getTag()
          This method is used to get the tag from a received SNMP message.
 boolean isInteger()
          This method is used to check whether the tag is an integer.
 boolean isIPAddress()
          This method is used to check whether the tag is an IP address.
 boolean isMessageSequence()
          This method is used to check whether the tag is a message sequence.
 boolean isOctetString()
          This method is used to check whether the tag is an octet string.
 boolean isOID()
          This method is used to check whether the tag is an OID.
 boolean isTimeTicks()
          This method is used to check whether the tag is a TimeTicks.
 void setBookMark()
          This method sets the bookmark.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

decodeLength

public int decodeLength()
                 throws java.lang.ArrayIndexOutOfBoundsException
Decodes an ASN.1 length field of an SNMP packet. The length field can have a minimum of 1 to a maximum of 4 bytes. In terms of decimal numbers it is from 0 to 2^31-1.
Throws:
java.lang.ArrayIndexOutOfBoundsException - When there is insufficient space in buffer.

decodeInteger

public int decodeInteger()
                  throws java.lang.ArrayIndexOutOfBoundsException
Decodes an ASN.1 Integer Only the least significant 4 bytes are retained
Throws:
java.lang.ArrayIndexOutOfBoundsException - When there is insufficient space in buffer.

decodeLong

public long[] decodeLong()
                  throws java.lang.ArrayIndexOutOfBoundsException
Decodes an ASN.1 Long Only the least significant 8 bytes are retained
Throws:
java.lang.ArrayIndexOutOfBoundsException - When there is insufficient space in buffer.

decodeOctetString

public byte[] decodeOctetString()
                         throws java.lang.ArrayIndexOutOfBoundsException
Decodes an ASN.1 Octet string. Only the primitive encoding is supported.
Throws:
java.lang.ArrayIndexOutOfBoundsException - When there is insufficient space in buffer.

decodeOID

public int[] decodeOID()
                throws java.lang.ArrayIndexOutOfBoundsException
Decodes an ASN.1 Object Identifier. SNMP limits OID length to 128 max. SNMP limits sub-identifiers to 32 bits.
Throws:
java.lang.ArrayIndexOutOfBoundsException - When there is insufficient space in buffer.

isMessageSequence

public boolean isMessageSequence()
This method is used to check whether the tag is a message sequence.

isInteger

public boolean isInteger()
This method is used to check whether the tag is an integer.

isOctetString

public boolean isOctetString()
This method is used to check whether the tag is an octet string.

isOID

public boolean isOID()
This method is used to check whether the tag is an OID.

isIPAddress

public boolean isIPAddress()
This method is used to check whether the tag is an IP address.

isTimeTicks

public boolean isTimeTicks()
This method is used to check whether the tag is a TimeTicks.

getTag

public byte getTag()
This method is used to get the tag from a received SNMP message.

decodeVarBindList

public void decodeVarBindList(java.util.Vector variables)
                       throws SnmpException
Throws:
SnmpException - is thrown whenever an error occurs.

encodeSequence

public void encodeSequence()
This method encodes the sequence.

setBookMark

public void setBookMark()
This method sets the bookmark. A bookmark is used to deal with some encodings.

getBookMark

public int getBookMark()
This method returns the bookmark value. A bookmark is used to deal with some encodings.
Returns:
the bookmark value.

getPosition

public int getPosition()
This method returns the position in the buffer where the the data will be encoded/decoded.
Returns:
the position in the buffer where the data will be next encoded/decoded.

getIndex

public int getIndex()
Returns the message index value. Message index is the offset value in the buffer while decoding messages.
Returns:
the index value.

encodeSequence

public void encodeSequence(byte type)
This method encodes the sequence.
Parameters:
type - the datatype

encodeSequence

public void encodeSequence(int length)
This method encodes the sequence.

encodeSequence

public void encodeSequence(int length,
                           byte type)
This method encodes the sequence.
Parameters:
type - the datatype
length - the length of data.

encodeInt

public void encodeInt(int value)
Encodes the data type int.
Parameters:
value - the int value.

encodeUInt

public void encodeUInt(int value)
Encodes the data type unsigned int.
Parameters:
value - the unsigned int value.

encodeString

public void encodeString(java.lang.String str)
Encodes the data type string.
Parameters:
str - the string value.

encodeOctets

public void encodeOctets(byte[] buf,
                         int length)
Encodes the octets specified. The data type is String.
Parameters:
buf - the value to be encoded.
length - the length of the value to be encoded.

encodeIPAddress

public void encodeIPAddress(SnmpString addr)
Encodes the IPAddress.
Parameters:
addr - The value to be encoded.

encodeEnterprise

public void encodeEnterprise(SnmpOID enterprise)
Encodes the enterprise.
Parameters:
enterprise - The value to be encoded.

encodeCommand

public void encodeCommand(byte command)
Encodes the command.
Parameters:
command - The value to be encoded.

encodeVarBindList

public void encodeVarBindList(java.util.Vector variables)
Encodes the VarBindList.
Parameters:
variables - The value to be encoded.

encrypt

public void encrypt(byte[] key,
                    byte[] privParms,
                    int protocol,
                    SecurityModelEntry utils)
             throws SnmpException
Encrypts the data.
Parameters:
key - The key value used in encryption.
privParms - The privacy params used in encryption.
protocol - The protocol used in encryption.
utils - The SecurityModelEntry implementation instance.
Throws:
SnmpException - if errors were encountered while encryption.

decrypt

public void decrypt(byte[] key,
                    byte[] privParms,
                    int protocol,
                    SecurityModelEntry utils)
             throws SnmpException
Decrypts the data.
Parameters:
key - The key value used in decryption.
privParms - The privacy params used in decryption.
protocol - The protocol used in decryption.
utils - The SecurityModelEntry implementation instance.
Throws:
SnmpException - if errors were encountered while decryption.

getReceivedData

public byte[] getReceivedData()
Returns the data. If decrypt method is called, it retruns the non decrypted data.
Returns:
The non decrypted data.

getData

public byte[] getData()
Returns the data. If decrypt method is already called, then it returns the decrypted data.
Returns:
the data.


Copyright (c)AdventNet Inc., 1996-2004