Class BERTag
java.lang.Object
javacardx.framework.tlv.BERTag
- Direct Known Subclasses:
ConstructedBERTag, PrimitiveBERTag
The abstract
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.
- Since:
- 2.2.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteConstant for BER Tag Class Applicationstatic final byteConstant for BER Tag Class Context-Specificstatic final byteConstant for BER Tag Class Privatestatic final byteConstant for BER Tag Class Universalstatic final booleanConstant for constructed BER Tag typestatic final booleanConstant for primitive BER Tag type -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBERTag()Constructor creates an emptyBERTLVTag object capable of encapsulating a BER TLV Tag. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares two Objects for equality.booleanComparesthisBER Tag with another.static BERTaggetInstance(byte[] bArray, short bOff) Create aBERTLVTag object from the binary representation in the byte array.abstract voidinit(byte[] bArray, short bOff) Abstract init method.booleanUsed to query ifthisBER tag structure is constructedstatic booleanisConstructed(byte[] berTagArray, short bOff) Returns the constructed flag part of the BER Tag from its representation in the specified byte arraybytesize()Returns the byte size required to representthistag structurestatic bytesize(byte[] berTagArray, short bOff) Returns the byte size required to represent the BER Tag from its representation in the specified byte arraybytetagClass()Returns the tag class part ofthisBER Tag structurestatic bytetagClass(byte[] berTagArray, short bOff) Returns the tag class part of the BER Tag from its representation in the specified byte arrayshortReturns the tag number part ofthisBER Tag structurestatic shorttagNumber(byte[] berTagArray, short bOff) Returns the tag number part of the BER Tag from its representation in the specified byte arrayshorttoBytes(byte[] outBuf, short bOffset) Writes the representation ofthisBER tag structure to the byte arraystatic shorttoBytes(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 booleanverifyFormat(byte[] berTagArray, short bOff) Checks if the input data is a well-formed BER Tag representation
-
Field Details
-
BER_TAG_CLASS_MASK_UNIVERSAL
public static final byte BER_TAG_CLASS_MASK_UNIVERSALConstant for BER Tag Class Universal- See Also:
-
BER_TAG_CLASS_MASK_APPLICATION
public static final byte BER_TAG_CLASS_MASK_APPLICATIONConstant for BER Tag Class Application- See Also:
-
BER_TAG_CLASS_MASK_CONTEXT_SPECIFIC
public static final byte BER_TAG_CLASS_MASK_CONTEXT_SPECIFICConstant for BER Tag Class Context-Specific- See Also:
-
BER_TAG_CLASS_MASK_PRIVATE
public static final byte BER_TAG_CLASS_MASK_PRIVATEConstant for BER Tag Class Private- See Also:
-
BER_TAG_TYPE_CONSTRUCTED
public static final boolean BER_TAG_TYPE_CONSTRUCTEDConstant for constructed BER Tag type- See Also:
-
BER_TAG_TYPE_PRIMITIVE
public static final boolean BER_TAG_TYPE_PRIMITIVEConstant for primitive BER Tag type- See Also:
-
-
Constructor Details
-
BERTag
protected BERTag()Constructor creates an emptyBERTLVTag 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.
-
-
Method Details
-
init
Abstract init method. (Re-)InitializethisBERTagobject 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- ifbArrayisnullTLVException- with the following reason codes:TLVException.ILLEGAL_SIZEif the tag number requested is larger than the supported maximum sizeTLVException.MALFORMED_TAGif tag representation in the byte array is malformed
-
getInstance
Create aBERTLVTag object from the binary representation in the byte array. All implementations must support tag numbers up to 0x3FFF. Note that the returnedBERTagmust be cast to the correct subclass:PrimitiveBERTagorConstructedBERTagto 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- ifbArrayisnullTLVException- with the following reason codes:TLVException.ILLEGAL_SIZEif the tag number requested is larger than the supported maximum sizeTLVException.MALFORMED_TAGif tag representation in the byte array is malformed.
-
size
Returns the byte size required to representthistag structure- Returns:
- size of BER Tag in bytes
- Throws:
TLVException- with the following reason codes:TLVException.TAG_SIZE_GREATER_THAN_127if the size of the BER Tag is > 127.TLVException.EMPTY_TAGif the BER Tag is empty.
-
toBytes
Writes the representation ofthisBER 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- ifoutBufisnullTLVException- with the following reason codes:TLVException.EMPTY_TAGif the BER Tag is empty.
-
tagNumber
Returns the tag number part ofthisBER Tag structure- Returns:
- the BER Tag tag number
- Throws:
TLVException- with the following reason codes:TLVException.TAG_NUMBER_GREATER_THAN_32767if the tag number is > 32767.TLVException.EMPTY_TAGif the BER Tag is empty.
-
isConstructed
public boolean isConstructed()Used to query ifthisBER tag structure is constructed- Returns:
trueif constructed,falseif primitive- Throws:
TLVException- with the following reason codes:TLVException.EMPTY_TAGif the BER Tag is empty.
-
tagClass
public byte tagClass()Returns the tag class part ofthisBER 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_TAGif the BER Tag is empty.
-
equals
ComparesthisBER Tag with another. Note that this method does not throw exceptions. If the parameterotherTagisnull, the method returnsfalse- Parameters:
otherTag- the reference BERTag with which to compare.- Returns:
trueif the tag data encapsulated are equal,falseotherwise
-
equals
Compares two Objects for equality.The
equalsmethod implements an equivalence relation:- It is reflexive: for any reference value
x,x.equals(x)should returntrue. - It is symmetric: for any reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse. - For any reference value
x,x.equals(null)should returnfalse.
The
equalsmethod for classObjectimplements the most discriminating possible equivalence relation on objects; that is, for any reference valuesxandy, this method returnstrueif and only ifxandyrefer to the same object (x==yhas 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- ifoutArrayisnullTLVException- with the following reason codes:TLVException.ILLEGAL_SIZEif the tag size is larger than the supported maximum size or 32767TLVException.INVALID_PARAMiftagClassparameter is invalid or if thetagNumberparameter is negative
-
size
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- ifberTagArrayisnullTLVException- with the following reason codes:TLVException.ILLEGAL_SIZEif the size of the BER Tag is greater than the maximum Tag size supportedTLVException.TAG_SIZE_GREATER_THAN_127if the size of the BER Tag is > 127.TLVException.MALFORMED_TAGif tag representation in the byte array is malformed
-
tagNumber
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- ifberTagArrayisnullTLVException- with the following reason codes:TLVException.ILLEGAL_SIZEif the size of the BER Tag is greater than the maximum Tag size supportedTLVException.TAG_NUMBER_GREATER_THAN_32767if the tag number is > 32767.TLVException.MALFORMED_TAGif 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:
trueif constructed,falseif primitive- Throws:
ArrayIndexOutOfBoundsException- if accessing the input array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException- ifberTagArrayisnullTLVException- with the following reason codes:TLVException.MALFORMED_TAGif 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- ifberTagArrayisnullTLVException- with the following reason codes:TLVException.MALFORMED_TAGif 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:
trueif input data is a well formed BER Tag structure of tag size equal to or less than the supported maximum size,falseotherwise- Throws:
ArrayIndexOutOfBoundsException- if accessing the input array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException- ifberTagArrayisnull
-