public class BER extends Object
Modifier and Type | Class and Description |
---|---|
static class |
BER.MutableByte
The
MutableByte class serves for exchanging type information
from the various decode* methods. |
Modifier and Type | Field and Description |
---|---|
static byte |
ASN_APPLICATION |
static byte |
ASN_BIT_STR |
static byte |
ASN_BIT8 |
static byte |
ASN_BOOLEAN |
static byte |
ASN_CONSTRUCTOR |
static byte |
ASN_CONTEXT |
static byte |
ASN_EXTENSION_ID |
static byte |
ASN_INTEGER |
static byte |
ASN_LONG_LEN |
static byte |
ASN_NULL |
static byte |
ASN_OBJECT_ID |
static byte |
ASN_OCTET_STR |
static byte |
ASN_PRIMITIVE |
static byte |
ASN_PRIVATE |
static byte |
ASN_SEQUENCE |
static byte |
ASN_SET |
static byte |
ASN_UNIVERSAL |
static byte |
BITSTRING |
static byte |
COUNTER |
static byte |
COUNTER32 |
static byte |
COUNTER64 |
static int |
ENDOFMIBVIEW |
static byte |
GAUGE |
static byte |
GAUGE32 |
static byte |
INTEGER |
static byte |
INTEGER32 |
static byte |
IPADDRESS |
static int |
MAX_OID_LENGTH |
static int |
NOSUCHINSTANCE |
static int |
NOSUCHOBJECT |
static byte |
NULL |
static byte |
OCTETSTRING |
static byte |
OID |
static byte |
OPAQUE |
static byte |
SEQUENCE |
static byte |
TIMETICKS |
Constructor and Description |
---|
BER() |
Modifier and Type | Method and Description |
---|---|
static void |
checkSequenceLength(int expectedLength,
BERSerializable sequence) |
static void |
checkSequenceLength(int expectedLength,
int actualLength,
BERSerializable sequence) |
static BigInteger |
decodeBigInteger(BERInputStream is,
BER.MutableByte type) |
static int |
decodeHeader(BERInputStream is,
BER.MutableByte type)
Decodes an ASN.1 header for an object with the ID and
length specified.
|
static int |
decodeHeader(BERInputStream is,
BER.MutableByte type,
boolean checkLength)
Decodes an ASN.1 header for an object with the ID and
length specified.
|
static int |
decodeInteger(BERInputStream is,
BER.MutableByte type) |
static int |
decodeLength(BERInputStream is)
Decodes a ASN.1 length.
|
static int |
decodeLength(BERInputStream is,
boolean checkLength)
Decodes a ASN.1 length.
|
static void |
decodeNull(BERInputStream is,
BER.MutableByte type) |
static int[] |
decodeOID(BERInputStream is,
BER.MutableByte type) |
static byte[] |
decodeString(BERInputStream is,
BER.MutableByte type) |
static long |
decodeUnsignedInt64(BERInputStream is,
BER.MutableByte type) |
static long |
decodeUnsignedInteger(BERInputStream is,
BER.MutableByte type) |
static void |
encodeBigInteger(OutputStream os,
byte type,
BigInteger value)
Encode a signed integer.
|
static void |
encodeHeader(OutputStream os,
int type,
int length)
Encodes an ASN.1 header for an object with the ID and
length specified.
|
static void |
encodeHeader(OutputStream os,
int type,
int length,
int numBytesLength)
Encodes an ASN.1 header for an object with the ID and
length specified with a fixed length of the encoded length as supplied.
|
static void |
encodeInteger(OutputStream os,
byte type,
int value)
Encode a signed integer.
|
static void |
encodeLength(OutputStream os,
int length)
Encodes the length of an ASN.1 object.
|
static void |
encodeLength(OutputStream os,
int length,
int numLengthBytes)
Encodes the length of an ASN.1 object.
|
static void |
encodeOID(OutputStream os,
byte type,
int[] oid)
Encode an ASN.1 oid filled with the supplied oid value.
|
static void |
encodeSequence(OutputStream os,
byte type,
int length)
Encode an ASN.1 header for a sequence with the ID and length specified.
|
static void |
encodeString(OutputStream os,
byte type,
byte[] string)
Encode an ASN.1 octet string filled with the supplied input string.
|
static void |
encodeUnsignedInt64(OutputStream os,
byte type,
long value) |
static void |
encodeUnsignedInteger(OutputStream os,
byte type,
long value)
Encode an unsigned integer.
|
static int |
getBERLengthOfLength(int length)
Compute the space needed to encode the length.
|
static int |
getBigIntegerBERLength(BigInteger value)
Get the BER encoded length of a BigInteger value.
|
static int |
getOIDLength(int[] value)
Gets the payload length in bytes of the BER encoded OID value.
|
static boolean |
isCheckFirstSubID012() |
static boolean |
isCheckSequenceLength()
Gets the SEQUENCE length checking mode.
|
boolean |
isCheckValueLength() |
static void |
setCheckFirstSubID012(boolean checkFirstSubID012) |
static void |
setCheckSequenceLength(boolean checkSequenceLen)
Sets the application wide SEQUENCE length checking mode.
|
void |
setCheckValueLength(boolean checkValueLength) |
public static final byte ASN_BOOLEAN
public static final byte ASN_INTEGER
public static final byte ASN_BIT_STR
public static final byte ASN_OCTET_STR
public static final byte ASN_NULL
public static final byte ASN_OBJECT_ID
public static final byte ASN_SEQUENCE
public static final byte ASN_SET
public static final byte ASN_UNIVERSAL
public static final byte ASN_APPLICATION
public static final byte ASN_CONTEXT
public static final byte ASN_PRIVATE
public static final byte ASN_PRIMITIVE
public static final byte ASN_CONSTRUCTOR
public static final byte ASN_LONG_LEN
public static final byte ASN_EXTENSION_ID
public static final byte ASN_BIT8
public static final byte INTEGER
public static final byte INTEGER32
public static final byte BITSTRING
public static final byte OCTETSTRING
public static final byte NULL
public static final byte OID
public static final byte SEQUENCE
public static final byte IPADDRESS
public static final byte COUNTER
public static final byte COUNTER32
public static final byte GAUGE
public static final byte GAUGE32
public static final byte TIMETICKS
public static final byte OPAQUE
public static final byte COUNTER64
public static final int NOSUCHOBJECT
public static final int NOSUCHINSTANCE
public static final int ENDOFMIBVIEW
public static final int MAX_OID_LENGTH
public static void encodeHeader(OutputStream os, int type, int length) throws IOException
os
- an OutputStream
to which the header is encoded.type
- the type of the ASN.1 object. Must be < 30, i.e. no extension octets.length
- the length of the object. The maximum length is 0xFFFFFFFF;IOException
- if the output stream fails to store the encoded header.public static void encodeHeader(OutputStream os, int type, int length, int numBytesLength) throws IOException
os
- an OutputStream
to which the header is encoded.type
- the type of the ASN.1 object. Must be < 30, i.e. no extension octets.length
- the length of the object. The maximum length is 0xFFFFFFFF;numBytesLength
- the number of bytes used to encode the length of the length.IOException
- if the output stream fails to store the encoded header.public static int getBERLengthOfLength(int length)
length
- Length to encodelength
public static void encodeLength(OutputStream os, int length) throws IOException
os
- an OutputStream
to which the length is encoded.length
- the length of the object. The maximum length is 0xFFFFFFFF;IOException
- if the output stream fails to store the encoded length.public static void encodeLength(OutputStream os, int length, int numLengthBytes) throws IOException
os
- an OutputStream
to which the length is encoded.length
- the length of the object. The maximum length is 0xFFFFFFFF;numLengthBytes
- the number of bytes to be used to encode the length using the long
form.IOException
- if the output stream fails to store the encoded length.public static void encodeInteger(OutputStream os, byte type, int value) throws IOException
os
- an OutputStream
to which the length is encoded.type
- the tag type for the integer (typically 0x02)value
- the integer value to encode.IOException
- if the output stream fails to store the encoded integer.public static void encodeBigInteger(OutputStream os, byte type, BigInteger value) throws IOException
os
- an OutputStream
to which the length is encoded.type
- the tag type for the integer (typically 0x02)value
- the integer value to encode.IOException
- if the output stream fails to store the encoded integer.public static int getBigIntegerBERLength(BigInteger value)
value
- a BigInteger value with a length that is less 2^31.public static void encodeUnsignedInteger(OutputStream os, byte type, long value) throws IOException
os
- an OutputStream
to which the length is encoded.type
- the tag type for the integer (typically 0x02)value
- the integer value to encode.IOException
- if the output stream fails to store the encoded value.public static void encodeString(OutputStream os, byte type, byte[] string) throws IOException
os
- an OutputStream
to which the length is encoded.type
- the tag type for the integer (typically 0x02)string
- the byte
array containing the octet string value.IOException
- if the output stream fails to store the encoded value.public static void encodeSequence(OutputStream os, byte type, int length) throws IOException
os
- an OutputStream
to which the length is encoded.type
- the tag type for the integer (typically 0x02)length
- the length of the sequence to encode.IOException
- if the output stream fails to store the encoded value.public static int getOIDLength(int[] value)
value
- an array of unsigned integer values representing an object identifier.public static void encodeOID(OutputStream os, byte type, int[] oid) throws IOException
os
- an OutputStream
to which the length is encoded.type
- the tag type for the integer (typically 0x06)oid
- the int
array containing the OID value.IOException
- if the output stream fails to store the encoded value.public static void encodeUnsignedInt64(OutputStream os, byte type, long value) throws IOException
IOException
public static int decodeLength(BERInputStream is) throws IOException
is
- an InputStream
IOException
- if the input stream contains an invalid BER encoding or an IO
exception occurred while reading from the stream.public static int decodeLength(BERInputStream is, boolean checkLength) throws IOException
is
- an InputStream
checkLength
- if false
length check is always suppressed.IOException
- if the input stream contains an invalid BER encoding or an IO
exception occurred while reading from the stream.public static int decodeHeader(BERInputStream is, BER.MutableByte type, boolean checkLength) throws IOException
is
- the BERInputStream to decode.type
- returns the type of the object at the current position in the input
stream.checkLength
- if false
length check is always suppressed.IOException
- if the input stream contains an invalid BER encoding or an IO
exception occurred while reading from the stream.public static int decodeHeader(BERInputStream is, BER.MutableByte type) throws IOException
is
- the BERInputStream to decode.type
- returns the type of the object at the current position in the input
stream.IOException
- if the input stream contains an invalid BER encoding or an IO
exception occurred while reading from the stream.public static int decodeInteger(BERInputStream is, BER.MutableByte type) throws IOException
IOException
public static BigInteger decodeBigInteger(BERInputStream is, BER.MutableByte type) throws IOException
IOException
public static long decodeUnsignedInteger(BERInputStream is, BER.MutableByte type) throws IOException
IOException
public static byte[] decodeString(BERInputStream is, BER.MutableByte type) throws IOException
IOException
public static int[] decodeOID(BERInputStream is, BER.MutableByte type) throws IOException
IOException
public static void decodeNull(BERInputStream is, BER.MutableByte type) throws IOException
IOException
public static long decodeUnsignedInt64(BERInputStream is, BER.MutableByte type) throws IOException
IOException
public static boolean isCheckSequenceLength()
true
if the length of a parsed SEQUENCE should be checked
against the real length of the objects parsed.public static void setCheckSequenceLength(boolean checkSequenceLen)
checkSequenceLen
- specifies whether he length of a parsed SEQUENCE should be checked
against the real length of the objects parsed.public static void checkSequenceLength(int expectedLength, BERSerializable sequence) throws IOException
IOException
public static void checkSequenceLength(int expectedLength, int actualLength, BERSerializable sequence) throws IOException
IOException
public boolean isCheckValueLength()
public void setCheckValueLength(boolean checkValueLength)
public static boolean isCheckFirstSubID012()
public static void setCheckFirstSubID012(boolean checkFirstSubID012)
Copyright © 2018 SNMP4J.org. All rights reserved.