Package javacardx.framework.tlv
Class BERTag
- java.lang.Object
-
- javacardx.framework.tlv.BERTag
-
- Direct Known Subclasses:
ConstructedBERTag
,PrimitiveBERTag
public abstract class BERTag extends Object
The abstractBERTag
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 subclassesConstructedBERTag
andPrimitiveBERTag
, also provide static methods to parse or edit a BER Tag structure representation in a byte array.- Since:
- 2.2.2
-
-
Field Summary
Fields Modifier and Type Field Description static byte
BER_TAG_CLASS_MASK_APPLICATION
Constant for BER Tag Class Applicationstatic byte
BER_TAG_CLASS_MASK_CONTEXT_SPECIFIC
Constant for BER Tag Class Context-Specificstatic byte
BER_TAG_CLASS_MASK_PRIVATE
Constant for BER Tag Class Privatestatic byte
BER_TAG_CLASS_MASK_UNIVERSAL
Constant for BER Tag Class Universalstatic boolean
BER_TAG_TYPE_CONSTRUCTED
Constant for constructed BER Tag typestatic boolean
BER_TAG_TYPE_PRIMITIVE
Constant for primitive BER Tag type
-
Constructor Summary
Constructors Modifier Constructor Description protected
BERTag()
Constructor creates an emptyBERTLV
Tag object capable of encapsulating a BER TLV Tag.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object otherTag)
Compares two Objects for equality.boolean
equals(BERTag otherTag)
Comparesthis
BER Tag with another.static BERTag
getInstance(byte[] bArray, short bOff)
Create aBERTLV
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 ifthis
BER tag structure is constructedstatic boolean
isConstructed(byte[] berTagArray, short bOff)
Returns the constructed flag part of the BER Tag from its representation in the specified byte arraybyte
size()
Returns the byte size required to representthis
tag structurestatic byte
size(byte[] berTagArray, short bOff)
Returns the byte size required to represent the BER Tag from its representation in the specified byte arraybyte
tagClass()
Returns the tag class part ofthis
BER Tag structurestatic byte
tagClass(byte[] berTagArray, short bOff)
Returns the tag class part of the BER Tag from its representation in the specified byte arrayshort
tagNumber()
Returns the tag number part ofthis
BER Tag structurestatic short
tagNumber(byte[] berTagArray, short bOff)
Returns the tag number part of the BER Tag from its representation in the specified byte arrayshort
toBytes(byte[] outBuf, short bOffset)
Writes the representation ofthis
BER tag structure to the byte arraystatic 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 arraystatic boolean
verifyFormat(byte[] berTagArray, short bOff)
Checks if the input data is a well-formed BER Tag representation
-
-
-
Field Detail
-
BER_TAG_CLASS_MASK_UNIVERSAL
public static final byte BER_TAG_CLASS_MASK_UNIVERSAL
Constant for BER Tag Class Universal- See Also:
- Constant Field Values
-
BER_TAG_CLASS_MASK_APPLICATION
public static final byte BER_TAG_CLASS_MASK_APPLICATION
Constant for BER Tag Class Application- See Also:
- Constant Field Values
-
BER_TAG_CLASS_MASK_CONTEXT_SPECIFIC
public static final byte BER_TAG_CLASS_MASK_CONTEXT_SPECIFIC
Constant for BER Tag Class Context-Specific- See Also:
- Constant Field Values
-
BER_TAG_CLASS_MASK_PRIVATE
public static final byte BER_TAG_CLASS_MASK_PRIVATE
Constant for BER Tag Class Private- See Also:
- Constant Field Values
-
BER_TAG_TYPE_CONSTRUCTED
public static final boolean BER_TAG_TYPE_CONSTRUCTED
Constant for constructed BER Tag type- See Also:
- Constant Field Values
-
BER_TAG_TYPE_PRIMITIVE
public static final boolean BER_TAG_TYPE_PRIMITIVE
Constant for primitive BER Tag type- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public abstract void init(byte[] bArray, short bOff) throws TLVException
Abstract init method. (Re-)Initializethis
BERTag
object from the binary representation in the byte array. All implementations must support tag numbers up to 0x3FFF.- Parameters:
bArray
- the byte array containing the binary representationbOff
- the offset within bArray where the tag binary begins- Throws:
ArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException
- ifbArray
isnull
TLVException
- with the following reason codes:TLVException.ILLEGAL_SIZE
if the tag number requested is larger than the supported maximum sizeTLVException.MALFORMED_TAG
if tag representation in the byte array is malformed
-
getInstance
public static BERTag getInstance(byte[] bArray, short bOff) throws TLVException
Create aBERTLV
Tag object from the binary representation in the byte array. All implementations must support tag numbers up to 0x3FFF. Note that the returnedBERTag
must be cast to the correct subclass:PrimitiveBERTag
orConstructedBERTag
to access their specialized API.- Parameters:
bArray
- the byte array containing the binary representationbOff
- the offset within bArray where the tag binary begins- Returns:
- the BERTag object instance
- Throws:
ArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException
- ifbArray
isnull
TLVException
- with the following reason codes:TLVException.ILLEGAL_SIZE
if the tag number requested is larger than the supported maximum sizeTLVException.MALFORMED_TAG
if tag representation in the byte array is malformed.
-
size
public byte size() throws TLVException
Returns the byte size required to representthis
tag structure- Returns:
- size of BER Tag in bytes
- Throws:
TLVException
- 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.
-
toBytes
public short toBytes(byte[] outBuf, short bOffset) throws TLVException
Writes the representation ofthis
BER tag structure to the byte array- Parameters:
outBuf
- the byteArray where the BER tag is writtenbOffset
- offset within outBuf where BER tag value starts- Returns:
- size of BER Tag in bytes
- Throws:
ArrayIndexOutOfBoundsException
- if accessing the output array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException
- ifoutBuf
isnull
TLVException
- with the following reason codes:TLVException.EMPTY_TAG
if the BER Tag is empty.
-
tagNumber
public short tagNumber() throws TLVException
Returns the tag number part ofthis
BER Tag structure- Returns:
- the BER Tag tag number
- Throws:
TLVException
- 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.
-
isConstructed
public boolean isConstructed()
Used to query ifthis
BER tag structure is constructed- Returns:
true
if constructed,false
if primitive- Throws:
TLVException
- with the following reason codes:TLVException.EMPTY_TAG
if the BER Tag is empty.
-
tagClass
public byte tagClass()
Returns the tag class part ofthis
BER Tag structure- Returns:
- the BER Tag class. One of the
BER_TAG_CLASS_MASK_*
.. constants defined above, for exampleBER_TAG_CLASS_MASK_APPLICATION
. - Throws:
TLVException
- with the following reason codes:TLVException.EMPTY_TAG
if the BER Tag is empty.
-
equals
public boolean equals(BERTag otherTag)
Comparesthis
BER Tag with another. Note that this method does not throw exceptions. If the parameterotherTag
isnull
, the method returnsfalse
- Parameters:
otherTag
- the reference BERTag with which to compare.- Returns:
true
if the tag data encapsulated are equal,false
otherwise
-
equals
public boolean equals(Object otherTag)
Description copied from class:Object
Compares two Objects for equality.The
equals
method implements an equivalence relation:- It is reflexive: for any reference value
x
,x.equals(x)
should returntrue
. - It is symmetric: for any reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any reference values
x
andy
, multiple invocations ofx.equals(y)
consistently returntrue
or consistently returnfalse
. - For any reference value
x
,x.equals(null)
should returnfalse
.
The
equals
method for classObject
implements the most discriminating possible equivalence relation on objects; that is, for any reference valuesx
andy
, this method returnstrue
if and only ifx
andy
refer to the same object (x==y
has the valuetrue
). - It is reflexive: for any reference value
-
toBytes
public 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- Parameters:
tagClass
- encodes the tag class. Valid codes are theBER_TAG_CLASS_MASK_*
constants defined above, for exampleBER_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 byte- Returns:
- size of BER Tag output bytes
- Throws:
ArrayIndexOutOfBoundsException
- if accessing the output array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException
- ifoutArray
isnull
TLVException
- with the following reason codes:TLVException.ILLEGAL_SIZE
if the tag size is larger than the supported maximum size or 32767TLVException.INVALID_PARAM
iftagClass
parameter is invalid or if thetagNumber
parameter is negative
-
size
public static byte size(byte[] berTagArray, short bOff) throws TLVException
Returns the byte size required to represent the BER Tag from its representation in the specified byte array- Parameters:
berTagArray
- input byte array containing the BER Tag representationbOff
- offset within byte array containing first byte- Returns:
- size of BER Tag in bytes
- Throws:
ArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException
- ifberTagArray
isnull
TLVException
- with the following reason codes:TLVException.ILLEGAL_SIZE
if the size of the BER Tag is greater than the maximum Tag size supportedTLVException.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
-
tagNumber
public static short tagNumber(byte[] berTagArray, short bOff) throws TLVException
Returns the tag number part of the BER Tag from its representation in the specified byte array- Parameters:
berTagArray
- input byte arraybOff
- offset within byte array containing first byte- Returns:
- the BER Tag tag number
- Throws:
ArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException
- ifberTagArray
isnull
TLVException
- with the following reason codes:TLVException.ILLEGAL_SIZE
if the size of the BER Tag is greater than the maximum Tag size supportedTLVException.TAG_NUMBER_GREATER_THAN_32767
if the tag number is > 32767.TLVException.MALFORMED_TAG
if tag representation in the byte array is malformed.
-
isConstructed
public static boolean isConstructed(byte[] berTagArray, short bOff)
Returns the constructed flag part of the BER Tag from its representation in the specified byte array- Parameters:
berTagArray
- input byte arraybOff
- offset within byte array containing first byte- Returns:
true
if constructed,false
if primitive- Throws:
ArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException
- ifberTagArray
isnull
TLVException
- with the following reason codes:TLVException.MALFORMED_TAG
if tag representation in the byte array is malformed.
-
tagClass
public static byte tagClass(byte[] berTagArray, short bOff)
Returns the tag class part of the BER Tag from its representation in the specified byte array- Parameters:
berTagArray
- input byte arraybOff
- offset within byte array containing first byte- Returns:
- the BER Tag class. One of the
BER_TAG_CLASS_MASK_*
.. constants defined above, for exampleBER_TAG_CLASS_MASK_APPLICATION
. - Throws:
ArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException
- ifberTagArray
isnull
TLVException
- with the following reason codes:TLVException.MALFORMED_TAG
if tag representation in the byte array is malformed.
-
verifyFormat
public static boolean verifyFormat(byte[] berTagArray, short bOff)
Checks if the input data is a well-formed BER Tag representation- Parameters:
berTagArray
- input byte arraybOff
- offset within byte array containing first byte- Returns:
true
if input data is a well formed BER Tag structure of tag size equal to or less than the supported maximum size,false
otherwise- Throws:
ArrayIndexOutOfBoundsException
- if accessing the input array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException
- ifberTagArray
isnull
-
-