public class BerValue extends Object
Modifier and Type | Field and Description |
---|---|
static byte |
FALSE_VALUE
The encoded byte for a FALSE value
|
static byte |
TRUE_VALUE
The encoded byte for a TRUE value
|
Constructor and Description |
---|
BerValue()
The default constructor.
|
BerValue(byte[] value)
Creates a new Value from a byte[]
|
Modifier and Type | Method and Description |
---|---|
void |
addData(byte[] array)
Append some bytes to the data buffer.
|
void |
addData(ByteBuffer buffer)
Append some bytes to the data buffer.
|
static void |
encode(ByteBuffer buffer,
BitString bitString)
Encode a BIT STRING value
|
static void |
encode(ByteBuffer buffer,
boolean bool)
Encode a boolean value
|
static void |
encode(ByteBuffer buffer,
byte[] bytes)
Encode an OctetString value
|
static void |
encode(ByteBuffer buffer,
byte tag,
int value)
Encode an integer value
|
static void |
encode(ByteBuffer buffer,
int value)
Encode an integer value
|
static void |
encode(ByteBuffer buffer,
long value)
Encode a long value
|
static void |
encode(ByteBuffer buffer,
Oid oid)
Encode an OID value
|
static void |
encode(ByteBuffer buffer,
String string)
Encode a String value
|
static void |
encodeBoolean(Asn1Buffer buffer,
boolean bool)
Encode a boolean value
|
static void |
encodeBoolean(Asn1Buffer buffer,
byte tag,
boolean bool)
Encode a boolean value
|
static void |
encodeEnumerated(Asn1Buffer buffer,
byte tag,
int value)
Encode an enumerated value
|
static void |
encodeEnumerated(Asn1Buffer buffer,
int value)
Encode an enumerated value
|
static void |
encodeEnumerated(ByteBuffer buffer,
int value)
Encode an enumerated value
|
static void |
encodeInteger(Asn1Buffer buffer,
byte tag,
int value)
Encode an integer value, with a specific tag
|
static void |
encodeInteger(Asn1Buffer buffer,
byte tag,
long value)
Encode an integer value, with a specific tag
|
static void |
encodeInteger(Asn1Buffer buffer,
int value)
Encode an integer value
|
static void |
encodeInteger(Asn1Buffer buffer,
long value)
Encode an integer value
|
static void |
encodeOctetString(Asn1Buffer buffer,
byte[] data)
Encode an OctetString
|
static void |
encodeOctetString(Asn1Buffer buffer,
byte tag,
byte[] data)
Encode an OctetString
|
static void |
encodeOctetString(Asn1Buffer buffer,
byte tag,
String value)
Encode an OctetString
|
static void |
encodeOctetString(Asn1Buffer buffer,
String value)
Encode an OctetString
|
static void |
encodeSequence(Asn1Buffer buffer)
Encode a Sequence
|
static void |
encodeSequence(Asn1Buffer buffer,
byte tag)
Encode a Sequence, with a specific tag
|
static void |
encodeSequence(Asn1Buffer buffer,
byte tag,
int start)
Encode a Sequence, with a specific length and tag
|
static void |
encodeSequence(Asn1Buffer buffer,
int start)
Encode a Sequence, with a specific length
|
static void |
encodeSet(Asn1Buffer buffer)
Encode a Set
|
static void |
encodeSet(Asn1Buffer buffer,
byte tag)
Encode a Set, with a specific tag
|
static void |
encodeSet(Asn1Buffer buffer,
byte tag,
int start)
Encode a Set, with a specific length and tag
|
static void |
encodeSet(Asn1Buffer buffer,
int start)
Encode a Set, with a specific length
|
static byte[] |
getBytes(int value)
Utility function that return a byte array representing the Value We must
respect the ASN.1 BER encoding scheme :
|
static byte[] |
getBytes(long value)
Utility function that return a byte array representing the Value.
|
int |
getCurrentLength() |
byte[] |
getData()
Get the Values'data
|
static int |
getNbBytes(int value)
Utility function that return the number of bytes necessary to store an
integer value.
|
static int |
getNbBytes(long value)
Utility function that return the number of bytes necessary to store a
long value.
|
void |
init(int size)
Initialize the Value
|
void |
reset()
Reset the Value so that it can be reused
|
void |
setData(byte[] data)
Set a block of bytes in the Value
|
void |
setData(ByteBuffer data)
Set a block of bytes in the Value
|
String |
toString()
Return a string representing the Value
|
public static final byte TRUE_VALUE
public static final byte FALSE_VALUE
public BerValue(byte[] value)
value
- the associated valuepublic BerValue()
public void init(int size)
size
- The data size to allocate.public void reset()
public byte[] getData()
public void setData(ByteBuffer data)
data
- The data to set.public void addData(ByteBuffer buffer)
buffer
- The data to append.public void setData(byte[] data)
data
- The data to set.public void addData(byte[] array)
array
- The data to append.public int getCurrentLength()
public static int getNbBytes(int value)
value
- The value to store in a byte arraypublic static int getNbBytes(long value)
value
- The value to store in a byte arraypublic static byte[] getBytes(int value)
1) positive integer - [0 - 0x7F] : 0xVV - [0x80 - 0xFF] : 0x00 0xVV - [0x0100 - 0x7FFF] : 0xVV 0xVV - [0x8000 - 0xFFFF] : 0x00 0xVV 0xVV - [0x010000 - 0x7FFFFF] : 0xVV 0xVV 0xVV - [0x800000 - 0xFFFFFF] : 0x00 0xVV 0xVV 0xVV - [0x01000000 - 0x7FFFFFFF] : 0xVV 0xVV 0xVV 0xVV 2) Negative number - (~value) + 1
value
- The value to store in a byte arraypublic static byte[] getBytes(long value)
1) positive integer - [0 - 0x7F] : 0xVV - [0x80 - 0xFF] : 0x00 0xVV - [0x0100 - 0x7FFF] : 0xVV 0xVV - [0x8000 - 0xFFFF] : 0x00 0xVV 0xVV - [0x010000 - 0x7FFFFF] : 0xVV 0xVV 0xVV - [0x800000 - 0xFFFFFF] : 0x00 0xVV 0xVV 0xVV - [0x01000000 - 0x7FFFFFFF] : 0xVV 0xVV 0xVV 0xVV 2) Negative number - (~value) + 1They are encoded following the table (the
-1 -> FF FF FF FF FF FF FF [FF] -127 -> FF FF FF FF FF FF FF [81] -128 -> FF FF FF FF FF FF FF [80] -129 -> FF FF FF FF FF FF [FF 7F] -255 -> FF FF FF FF FF FF [FF 01] -256 -> FF FF FF FF FF FF [FF 00] -257 -> FF FF FF FF FF FF [FE FF] -32767 -> FF FF FF FF FF FF [80 01] -32768 -> FF FF FF FF FF FF [80 00] -32769 -> FF FF FF FF FF [FF 7F FF] -65535 -> FF FF FF FF FF [FF 00 01] -65536 -> FF FF FF FF FF [FF 00 00] -65537 -> FF FF FF FF FF [FE FF FF] -8388607 -> FF FF FF FF FF [80 00 01] -8388608 -> FF FF FF FF FF [80 00 00] -8388609 -> FF FF FF FF [FF 7F FF FF] -16777215 -> FF FF FF FF [FF 00 00 01] -16777216 -> FF FF FF FF [FF 00 00 00] -16777217 -> FF FF FF FF [FE FF FF FF] -2147483647 -> FF FF FF FF [80 00 00 01] -2147483648 -> FF FF FF FF [80 00 00 00] -2147483649 -> FF FF FF [FF 7F FF FF FF] -4294967295 -> FF FF FF [FF 00 00 00 01] -4294967296 -> FF FF FF [FF 00 00 00 00] -4294967297 -> FF FF FF [FE FF FF FF FF] -549755813887 -> FF FF FF [80 00 00 00 01] -549755813888 -> FF FF FF [80 00 00 00 00] -549755813889 -> FF FF [FF 7F FF FF FF FF] -1099511627775 -> FF FF [FF 00 00 00 00 01] -1099511627776 -> FF FF [FF 00 00 00 00 00] -1099511627777 -> FF FF [FE FF FF FF FF FF] -140737488355327 -> FF FF [80 00 00 00 00 01] -140737488355328 -> FF FF [80 00 00 00 00 00] -140737488355329 -> FF [FF 7F FF FF FF FF FF] -281474976710655 -> FF [FF 00 00 00 00 00 01] -281474976710656 -> FF [FF 00 00 00 00 00 00] -281474976710657 -> FF [FE FF FF FF FF FF FF] -36028797018963967 -> FF [80 00 00 00 00 00 01] -36028797018963968 -> FF [80 00 00 00 00 00 00] -36028797018963969 -> [FF 7F FF FF FF FF FF FF] -72057594037927936 -> [FF 00 00 00 00 00 00 00] -72057594037927937 -> [FE FF FF FF FF FF FF FF] -9223372036854775807 -> [80 00 00 00 00 00 00 01] -9223372036854775808 -> [80 00 00 00 00 00 00 00]
value
- The value to store in a byte arraypublic static void encodeBoolean(Asn1Buffer buffer, boolean bool)
buffer
- The PDU in which the value will be putbool
- The boolean to be encodedpublic static void encodeBoolean(Asn1Buffer buffer, byte tag, boolean bool)
buffer
- The PDU in which the value will be puttag
- the TAG to usebool
- The boolean to be encodedpublic static void encodeInteger(Asn1Buffer buffer, int value)
buffer
- The PDU in which the value will be putvalue
- The integer to be encodedpublic static void encodeInteger(Asn1Buffer buffer, byte tag, int value)
buffer
- The PDU in which the value will be puttag
- The tag to usevalue
- The integer to be encodedpublic static void encodeInteger(Asn1Buffer buffer, long value)
buffer
- The PDU in which the value will be putvalue
- The long to be encodedpublic static void encodeInteger(Asn1Buffer buffer, byte tag, long value)
buffer
- The PDU in which the value will be puttag
- The tag to usevalue
- The long to be encodedpublic static void encodeOctetString(Asn1Buffer buffer, byte[] data)
buffer
- The PDU in which the value will be putdata
- The byte[] to be encodedpublic static void encodeOctetString(Asn1Buffer buffer, String value)
buffer
- The PDU in which the value will be putvalue
- The String to be encodedpublic static void encodeOctetString(Asn1Buffer buffer, byte tag, byte[] data)
buffer
- The PDU in which the value will be puttag
- The tag to usedata
- The OctetString to be encodedpublic static void encodeOctetString(Asn1Buffer buffer, byte tag, String value)
buffer
- The PDU in which the value will be puttag
- The tag to usevalue
- The OctetString to be encodedpublic static void encodeSequence(Asn1Buffer buffer)
buffer
- The PDU in which the Sequence will be putpublic static void encodeSequence(Asn1Buffer buffer, int start)
buffer
- The PDU in which the Sequence will be putstart
- The Sequence lengthpublic static void encodeSequence(Asn1Buffer buffer, byte tag)
buffer
- The PDU in which the Sequence will be puttag
- The tag to usepublic static void encodeSequence(Asn1Buffer buffer, byte tag, int start)
buffer
- The PDU in which the Sequence will be puttag
- The tag to usestart
- The position in the buffer this Sequence startspublic static void encodeSet(Asn1Buffer buffer)
buffer
- The PDU in which the Set will be putpublic static void encodeSet(Asn1Buffer buffer, int start)
buffer
- The PDU in which the Set will be putstart
- The Set lengthpublic static void encodeSet(Asn1Buffer buffer, byte tag)
buffer
- The PDU in which the value will be puttag
- The tag to usepublic static void encodeSet(Asn1Buffer buffer, byte tag, int start)
buffer
- The PDU in which the set will be puttag
- The tag to usestart
- The position in the buffer this Set startspublic static void encode(ByteBuffer buffer, String string) throws EncoderException
buffer
- The PDU in which the value will be putstring
- The String to be encoded. It is supposed to be UTF-8EncoderException
- if the PDU in which the value should be encoded is
two smallpublic static void encode(ByteBuffer buffer, BitString bitString) throws EncoderException
buffer
- The PDU in which the value will be putbitString
- The BitString to be encoded.EncoderException
- if the PDU in which the value should be encoded is
two smallpublic static void encode(ByteBuffer buffer, byte[] bytes) throws EncoderException
buffer
- The PDU in which the value will be putbytes
- The bytes to be encodedEncoderException
- if the PDU in which the value should be encoded is
two smallpublic static void encode(ByteBuffer buffer, Oid oid) throws EncoderException
buffer
- The PDU in which the value will be putoid
- The OID to be encodedEncoderException
- if the PDU in which the value should be encoded is
two smallpublic static void encode(ByteBuffer buffer, int value) throws EncoderException
buffer
- The PDU in which the value will be putvalue
- The integer to be encodedEncoderException
- if the PDU in which the value should be encoded is
two smallpublic static void encode(ByteBuffer buffer, long value) throws EncoderException
buffer
- The PDU in which the value will be putvalue
- The long to be encodedEncoderException
- if the PDU in which the value should be encoded is
two smallpublic static void encode(ByteBuffer buffer, byte tag, int value) throws EncoderException
buffer
- The PDU in which the value will be puttag
- The tag if it's not an UNIVERSAL onevalue
- The integer to be encodedEncoderException
- if the PDU in which the value should be encoded is
two smallpublic static void encodeEnumerated(Asn1Buffer buffer, int value)
buffer
- The PDU in which the value will be putvalue
- The integer to be encodedpublic static void encodeEnumerated(Asn1Buffer buffer, byte tag, int value)
buffer
- The PDU in which the value will be puttag
- The tag to usevalue
- The integer to be encodedpublic static void encodeEnumerated(ByteBuffer buffer, int value) throws EncoderException
buffer
- The PDU in which the value will be putvalue
- The integer to be encodedEncoderException
- if the PDU in which the value should be encoded is
two smallpublic static void encode(ByteBuffer buffer, boolean bool) throws EncoderException
buffer
- The PDU in which the value will be putbool
- The boolean to be encodedEncoderException
- if the PDU in which the value should be encoded is
two smallCopyright © 2003–2020 The Apache Software Foundation. All rights reserved.