Package javacardx.framework.tlv
Class BERTLV
- java.lang.Object
-
- javacardx.framework.tlv.BERTLV
-
- Direct Known Subclasses:
ConstructedBERTLV,PrimitiveBERTLV
public abstract class BERTLV extends Object
The abstractBERTLVclass encapsulates a BER TLV structure. The rules on the allowed encoding of the Tag, length and value fields are based on the ASN.1 BER encoding rules ISO/IEC 8825-1:2002.The
BERTLVclass and the subclasses -ConstructedBERTLVandPrimitiveBERTLVonly support encoding of the length(L) octets in definite form. These classes do not provide support for the encoding rules of the contents octets of the value(V) field as described in ISO/IEC 8825-1:2002.The
BERTLVclass and the subclasses -ConstructedBERTLVandPrimitiveBERTLValso provide static methods to parse/edit a TLV structure representation in a byte array.- Since:
- 2.2.2
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBERTLV()Constructor creates an emptyBERTLVobject capable of encapsulating a BER TLV structure.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static BERTLVgetInstance(byte[] bArray, short bOff, short bLen)Creates theBERTLVusing the input binary data.shortgetLength()Returns the value ofthisTLV object's Length componentstatic shortgetLength(byte[] berTLVArray, short bOff)Returns the value of the TLV Structure's Length component in the specified input byte arrayBERTaggetTag()Returnsthisvalue of the TLV object's Tag componentstatic shortgetTag(byte[] berTLVArray, short bTLVOff, byte[] berTagArray, short bTagOff)Copies the tag component in the TLV representation in the specified input byte array to the specified output byte arrayabstract shortinit(byte[] bArray, short bOff, short bLen)Abstract init method.shortsize()Returns the number of bytes required to representthisTLV structureshorttoBytes(byte[] outBuf, short bOff)WritesthisTLV structure to the specified byte array.static booleanverifyFormat(byte[] berTlvArray, short bOff, short bLen)Checks if the input data is a well-formed BER TLV representation.
-
-
-
Method Detail
-
init
public abstract short init(byte[] bArray, short bOff, short bLen) throws TLVExceptionAbstract init method. (Re-)InitializesthisBERTLVusing the input byte data.The capacity of
thisBERTLVis increased, if required and supported, based on the size of the input TLV data structure.Note:
- If
bOff+bLenis greater thanbArray.length, the length of thebArrayarray, anArrayIndexOutOfBoundsExceptionexception is thrown.
- Parameters:
bArray- input byte arraybOff- offset within byte array containing the TLV databLen- byte length of input data- Returns:
- the resulting size of
thisTLV if represented in bytes - Throws:
ArrayIndexOutOfBoundsException- if accessing the input array would cause access of data outside array bounds, or if the array offset or array length parameter is negativeNullPointerException- ifbArrayisnullTLVException- with the following reason codes:TLVException.INSUFFICIENT_STORAGEif the required capacity is not available and the implementation does not support automatic expansion.TLVException.MALFORMED_TLVif the input data is not a well-formed BER TLV or the input data represents a primitive BER TLV structure andthisis aConstructedBERTLVobject or the input data represents a constructed BER TLV structure andthisis aPrimiitveBERTLVobject.
- If
-
getInstance
public static BERTLV getInstance(byte[] bArray, short bOff, short bLen) throws TLVException
Creates theBERTLVusing the input binary data. The resulting BER TLV object may be a primitive or a constructed TLV object. The object must be cast to the correct sub-class:ConstructedBERTLVorPrimitiveBERTLVto access the specialized API. Theinit( byte[] bArray, short bOff, short bLen )methods of the appropriateBERTLVclasses will be used to initialize the created TLV object.Note:
- If
bOff+bLenis greater thanbArray.length, the length of thebArrayarray, anArrayIndexOutOfBoundsExceptionexception is thrown.
- Parameters:
bArray- input byte arraybOff- offset within byte array containing the tlv databLen- byte length of input data- Returns:
- the BERTLV object instance
- Throws:
ArrayIndexOutOfBoundsException- if accessing the input array would cause access of data outside array bounds, or if the array offset or array length parameter is negativeNullPointerException- ifbArrayisnullTLVException- with the following reason codes:TLVException.ILLEGAL_SIZEif the TLV structure requested is larger than the supported maximum sizeTLVException.MALFORMED_TLVif the input data is not a well-formed BER TLV.
- If
-
toBytes
public short toBytes(byte[] outBuf, short bOff)WritesthisTLV structure to the specified byte array.- Parameters:
outBuf- output byte arraybOff- offset within byte array output data begins- Returns:
- the byte length written to the output array
- 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.TLV_SIZE_GREATER_THAN_32767if the size of the BER TLV is > 32767.TLVException.EMPTY_TLVif theBERTLVobject is empty.
-
getTag
public BERTag getTag() throws TLVException
Returnsthisvalue of the TLV object's Tag component- Returns:
- the Tag for
thisBERTLVobject - Throws:
TLVException- with the following reason codes:TLVException.EMPTY_TLVif theBERTLVobject is empty.
-
getLength
public short getLength() throws TLVExceptionReturns the value ofthisTLV object's Length component- Returns:
- the value length of the TLV
- Throws:
TLVException- with the following reason codes:TLVException.TLV_LENGTH_GREATER_THAN_32767if the value of the Length component is > 32767.TLVException.EMPTY_TLVif theBERTLVobject is empty.
-
size
public short size()
Returns the number of bytes required to representthisTLV structure- Returns:
- the byte length of the TLV
- Throws:
TLVException- with the following reason codes:TLVException.TLV_SIZE_GREATER_THAN_32767if the size of TLV structure is > 32767.TLVException.EMPTY_TLVif theBERTLVobject is empty.
-
verifyFormat
public static boolean verifyFormat(byte[] berTlvArray, short bOff, short bLen)Checks if the input data is a well-formed BER TLV representation.Note:
- If
bOff+bLenis greater thanberTlvArray.length, the length of theberTlvArrayarray, anArrayIndexOutOfBoundsExceptionexception is thrown.
- Parameters:
berTlvArray- input byte arraybOff- offset within byte array containing first bytebLen- byte length of input BER TLV data- Returns:
trueif input data is a well formed BER TLV structure,falseotherwise- Throws:
ArrayIndexOutOfBoundsException- if accessing the input array would cause access of data outside array bounds, or if the array offset or array length parameter is negativeNullPointerException- ifberTlvArrayisnull
- If
-
getTag
public static short getTag(byte[] berTLVArray, short bTLVOff, byte[] berTagArray, short bTagOff) throws TLVExceptionCopies the tag component in the TLV representation in the specified input byte array to the specified output byte array- Parameters:
berTLVArray- input byte arraybTLVOff- offset within byte array containing the tlv databerTagArray- output Tag byte arraybTagOff- offset within byte array where output begins- Returns:
- the size of the output BER Tag
- Throws:
ArrayIndexOutOfBoundsException- if accessing the input or output array would cause access of data outside array bounds, or if either array offset parameter is negativeNullPointerException- if eitherberTLVArrayorberTagArrayisnullTLVException- with the following reason codes:TLVException.ILLEGAL_SIZEif the size of the Tag component is > 32767.TLVException.MALFORMED_TLVif the input data is not a well-formed BER TLV.
-
getLength
public static short getLength(byte[] berTLVArray, short bOff) throws TLVExceptionReturns the value of the TLV Structure's Length component in the specified input byte array- Parameters:
berTLVArray- input byte arraybOff- offset within byte array containing the tlv data- Returns:
- the length value in the TLV representation in the specified byte array
- Throws:
ArrayIndexOutOfBoundsException- if accessing the input array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException- ifberTLVArrayTLVException- with the following reason codes:TLVException.TLV_LENGTH_GREATER_THAN_32767if the length element(L) > 32767.TLVException.MALFORMED_TLVif the input data is not a well-formed BER TLV.
-
-