public abstract class BERTag extends Object
BERTag
class encapsulates a BER TLV tag. The
rules on the allowed encoding of the Tag field are based on the ASN.1 BER
encoding rules of ISO/IEC 8825-1:2002.
The BERTag
class and the subclasses
ConstructedBERTag
and PrimitiveBERTag
, also
provide static methods to parse or edit a BER Tag structure representation in
a byte array.
Modifier and Type | Field and Description |
---|---|
static byte |
BER_TAG_CLASS_MASK_APPLICATION
Constant for BER Tag Class Application
|
static byte |
BER_TAG_CLASS_MASK_CONTEXT_SPECIFIC
Constant for BER Tag Class Context-Specific
|
static byte |
BER_TAG_CLASS_MASK_PRIVATE
Constant for BER Tag Class Private
|
static byte |
BER_TAG_CLASS_MASK_UNIVERSAL
Constant for BER Tag Class Universal
|
static boolean |
BER_TAG_TYPE_CONSTRUCTED
Constant for constructed BER Tag type
|
static boolean |
BER_TAG_TYPE_PRIMITIVE
Constant for primitive BER Tag type
|
Modifier | Constructor and Description |
---|---|
protected |
BERTag()
Constructor creates an empty
BERTLV Tag object capable of
encapsulating a BER TLV Tag. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(BERTag otherTag)
Compares
this BER Tag with another. |
boolean |
equals(Object otherTag)
Compares two Objects for equality.
|
static BERTag |
getInstance(byte[] bArray,
short bOff)
Create a
BERTLV Tag object from the binary representation
in the byte array. |
abstract void |
init(byte[] bArray,
short bOff)
Abstract init method.
|
boolean |
isConstructed()
Used to query if
this BER tag structure is constructed |
static boolean |
isConstructed(byte[] berTagArray,
short bOff)
Returns the constructed flag part of the BER Tag from its representation
in the specified byte array
|
byte |
size()
Returns the byte size required to represent
this tag
structure |
static byte |
size(byte[] berTagArray,
short bOff)
Returns the byte size required to represent the BER Tag from its
representation in the specified byte array
|
byte |
tagClass()
Returns the tag class part of
this BER Tag structure |
static byte |
tagClass(byte[] berTagArray,
short bOff)
Returns the tag class part of the BER Tag from its representation in the
specified byte array
|
short |
tagNumber()
Returns the tag number part of
this BER Tag structure |
static short |
tagNumber(byte[] berTagArray,
short bOff)
Returns the tag number part of the BER Tag from its representation in the
specified byte array
|
short |
toBytes(byte[] outBuf,
short bOffset)
Writes the representation of
this BER tag structure to the
byte array |
static short |
toBytes(short tagClass,
boolean isConstructed,
short tagNumber,
byte[] outArray,
short bOff)
Writes the BER Tag bytes representing the specified tag class,
constructed flag and the tag number as a BER Tag representation in the
specified byte array
|
static boolean |
verifyFormat(byte[] berTagArray,
short bOff)
Checks if the input data is a well-formed BER Tag representation
|
public static final byte BER_TAG_CLASS_MASK_UNIVERSAL
public static final byte BER_TAG_CLASS_MASK_APPLICATION
public static final byte BER_TAG_CLASS_MASK_CONTEXT_SPECIFIC
public static final byte BER_TAG_CLASS_MASK_PRIVATE
public static final boolean BER_TAG_TYPE_CONSTRUCTED
public static final boolean BER_TAG_TYPE_PRIMITIVE
protected BERTag()
BERTLV
Tag object capable of
encapsulating a BER TLV Tag. All implementations must support at least 3
byte Tags which can encode tag numbers up to 0x3FFF.public abstract void init(byte[] bArray, short bOff) throws TLVException
this
BERTag
object from the binary
representation in the byte array. All implementations must support tag
numbers up to 0x3FFF.bArray
- the byte array containing the binary representationbOff
- the offset within bArray where the tag binary beginsArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data
outside array bounds, or if the array offset parameter is
negativeNullPointerException
- if bArray
is null
TLVException
- with the following reason codes:
TLVException.ILLEGAL_SIZE
if the tag
number requested is larger than the supported maximum size
TLVException.MALFORMED_TAG
if tag
representation in the byte array is malformed
public static BERTag getInstance(byte[] bArray, short bOff) throws TLVException
BERTLV
Tag object from the binary representation
in the byte array. All implementations must support tag numbers up to
0x3FFF. Note that the returned BERTag
must be cast to the
correct subclass: PrimitiveBERTag
or
ConstructedBERTag
to access their specialized API.bArray
- the byte array containing the binary representationbOff
- the offset within bArray where the tag binary beginsArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data
outside array bounds, or if the array offset parameter is
negativeNullPointerException
- if bArray
is null
TLVException
- with the following reason codes:
TLVException.ILLEGAL_SIZE
if the tag
number requested is larger than the supported maximum size
TLVException.MALFORMED_TAG
if tag
representation in the byte array is malformed.
public byte size() throws TLVException
this
tag
structureTLVException
- with the following reason codes:
TLVException.TAG_SIZE_GREATER_THAN_127
if the size of the BER Tag is > 127.
TLVException.EMPTY_TAG
if the BER Tag
is empty.
public short toBytes(byte[] outBuf, short bOffset) throws TLVException
this
BER tag structure to the
byte arrayoutBuf
- the byteArray where the BER tag is writtenbOffset
- offset within outBuf where BER tag value startsArrayIndexOutOfBoundsException
- if accessing the output array would cause access of data
outside array bounds, or if the array offset parameter is
negativeNullPointerException
- if outBuf
is null
TLVException
- with the following reason codes:
TLVException.EMPTY_TAG
if the BER Tag
is empty.
public short tagNumber() throws TLVException
this
BER Tag structureTLVException
- with the following reason codes:
TLVException.TAG_NUMBER_GREATER_THAN_32767
if the tag number is > 32767.
TLVException.EMPTY_TAG
if the BER Tag
is empty.
public boolean isConstructed()
this
BER tag structure is constructedtrue
if constructed, false
if
primitiveTLVException
- with the following reason codes:
TLVException.EMPTY_TAG
if the BER Tag
is empty.
public byte tagClass()
this
BER Tag structureBER_TAG_CLASS_MASK_*
..
constants defined above, for example
BER_TAG_CLASS_MASK_APPLICATION
.TLVException
- with the following reason codes:
TLVException.EMPTY_TAG
if the BER Tag
is empty.
public boolean equals(BERTag otherTag)
this
BER Tag with another. Note that this method
does not throw exceptions. If the parameter otherTag
is
null
, the method returns false
true
if the tag data encapsulated are equal,
false
otherwisepublic boolean equals(Object otherTag)
Object
The equals
method implements an equivalence relation:
x
,
x.equals(x)
should return true
.
x
and y
, x.equals(y)
should return
true
if and only if y.equals(x)
returns
true
.
x
,
y
, and z
, if x.equals(y)
returns true
and y.equals(z)
returns
true
, then x.equals(z)
should return
true
.
x
and y
, multiple invocations of x.equals(y)
consistently return true
or consistently return
false
.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements the most discriminating possible equivalence relation on
objects; that is, for any reference values x
and
y
, this method returns true
if and only if
x
and y
refer to the same object (x==y
has the value true
).
public static short toBytes(short tagClass, boolean isConstructed, short tagNumber, byte[] outArray, short bOff)
tagClass
- encodes the tag class. Valid codes are the
BER_TAG_CLASS_MASK_*
constants defined above, for example
BER_TAG_CLASS_MASK_APPLICATION
.isConstructed
- true if the tag is constructed, false if primitivetagNumber
- is the tag number.outArray
- output byte arraybOff
- offset within byte array containing first byteArrayIndexOutOfBoundsException
- if accessing the output array would cause access of data
outside array bounds, or if the array offset parameter is
negativeNullPointerException
- if outArray
is null
TLVException
- with the following reason codes:
TLVException.ILLEGAL_SIZE
if the tag
size is larger than the supported maximum size or 32767
TLVException.INVALID_PARAM
if
tagClass
parameter is invalid or if the
tagNumber
parameter is negative
public static byte size(byte[] berTagArray, short bOff) throws TLVException
berTagArray
- input byte array containing the BER Tag representationbOff
- offset within byte array containing first byteArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data
outside array bounds, or if the array offset parameter is
negativeNullPointerException
- if berTagArray
is null
TLVException
- with the following reason codes:
TLVException.ILLEGAL_SIZE
if the size
of the BER Tag is greater than the maximum Tag size
supported
TLVException.TAG_SIZE_GREATER_THAN_127
if the size of the BER Tag is > 127.
TLVException.MALFORMED_TAG
if tag
representation in the byte array is malformed
public static short tagNumber(byte[] berTagArray, short bOff) throws TLVException
berTagArray
- input byte arraybOff
- offset within byte array containing first byteArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data
outside array bounds, or if the array offset parameter is
negativeNullPointerException
- if berTagArray
is null
TLVException
- with the following reason codes:
TLVException.ILLEGAL_SIZE
if the size
of the BER Tag is greater than the maximum Tag size
supported
TLVException.TAG_NUMBER_GREATER_THAN_32767
if the tag number is > 32767.
TLVException.MALFORMED_TAG
if tag
representation in the byte array is malformed.
public static boolean isConstructed(byte[] berTagArray, short bOff)
berTagArray
- input byte arraybOff
- offset within byte array containing first bytetrue
if constructed, false
if
primitiveArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data
outside array bounds, or if the array offset parameter is
negativeNullPointerException
- if berTagArray
is null
TLVException
- with the following reason codes:
TLVException.MALFORMED_TAG
if tag
representation in the byte array is malformed.
public static byte tagClass(byte[] berTagArray, short bOff)
berTagArray
- input byte arraybOff
- offset within byte array containing first byteBER_TAG_CLASS_MASK_*
..
constants defined above, for example
BER_TAG_CLASS_MASK_APPLICATION
.ArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data
outside array bounds, or if the array offset parameter is
negativeNullPointerException
- if berTagArray
is null
TLVException
- with the following reason codes:
TLVException.MALFORMED_TAG
if tag
representation in the byte array is malformed.
public static boolean verifyFormat(byte[] berTagArray, short bOff)
berTagArray
- input byte arraybOff
- offset within byte array containing first bytetrue
if input data is a well formed BER Tag
structure of tag size equal to or less than the supported maximum
size, false
otherwiseArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data
outside array bounds, or if the array offset parameter is
negativeNullPointerException
- if berTagArray
is null
Copyright © 1998, 2015, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms