Class PrimitiveBERTLV
- java.lang.Object
-
- javacardx.framework.tlv.BERTLV
-
- javacardx.framework.tlv.PrimitiveBERTLV
-
public class PrimitiveBERTLV extends BERTLV
ThePrimitiveBERTLVclass encapsulates a primitive BER TLV structure. It extends the genericBERTLVclass. The rules on the allowed encoding of the Tag, length and value fields is based on the ASN.1 BER encoding rules ISO/IEC 8825-1:2002.The
PrimitiveBERTLVclass only supports encoding of the length(L) octets in definite form. The value(V) field which encodes the contents octets are merely viewed as a series of bytes.Every
PrimitiveBERTLVhas a capacity which represents the allocated internal buffer to represent the Value ofthisTLV object. As long as the number of bytes required to represent the Value of the TLV object does not exceed the capacity, it is not necessary to allocate additional internal buffer space. If the internal buffer overflows, and the implementation supports automatic expansion which might require new data allocation and possibly old data/object deletion, it is automatically made larger. Otherwise aTLVExceptionis thrown.The
BERTLVclass and the subclassesConstructedBERTLVandPrimitiveBERTLV, also provide static methods to parse or edit a TLV structure representation in a byte array.- Since:
- 2.2.2
-
-
Constructor Summary
Constructors Constructor Description PrimitiveBERTLV(short numValueBytes)Constructor creates an emptyPrimitiveBERTLVobject capable of encapsulating a Primitive BER TLV structure.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static shortappendValue(byte[] berTLVArray, short bTLVOff, byte[] vArray, short vOff, short vLen)Appends the specified data to the end of the Primitive TLV representation in the specified byte array.shortappendValue(byte[] vArray, short vOff, short vLen)Appends the specified data to the end ofthisPrimitive BER TLV object.shortgetValue(byte[] tlvValue, short tOff)Writes the value (V) part ofthisPrimitive BER TLV object into the output buffer.static shortgetValueOffset(byte[] berTLVArray, short bTLVOff)Returns the offset into the specified input byte array of the value (V) part of the BER TLV structure representation in the input array.shortinit(byte[] bArray, short bOff, short bLen)(Re-)InitializesthisPrimitiveBERTLVusing the input byte data.shortinit(PrimitiveBERTag tag, byte[] vArray, short vOff, short vLen)(Re-)InitializesthisPrimitiveBERTLVobject with the input tag, length and data.shortreplaceValue(byte[] vArray, short vOff, short vLen)Replaces the specified data in place of the current value ofthisPrimitive BER TLV object.static shorttoBytes(byte[] berTagArray, short berTagOff, byte[] valueArray, short vOff, short vLen, byte[] outBuf, short bOff)Writes a primitive TLV representation to the specified byte array using as input a Primitive BER tag representation in a byte array and a value representation in another byte array.-
Methods inherited from class javacardx.framework.tlv.BERTLV
getInstance, getLength, getLength, getTag, getTag, size, toBytes, verifyFormat
-
-
-
-
Constructor Detail
-
PrimitiveBERTLV
public PrimitiveBERTLV(short numValueBytes)
Constructor creates an emptyPrimitiveBERTLVobject capable of encapsulating a Primitive BER TLV structure.The initial capacity is specified by the numValueBytes argument.
- Parameters:
numValueBytes- is the number of Value bytes to allocate- Throws:
TLVException- with the following reason codes:TLVException.INVALID_PARAMif numValueBytes parameter is negative or larger than the maximum capacity supported by the implementation.
-
-
Method Detail
-
init
public short init(byte[] bArray, short bOff, short bLen) throws TLVException(Re-)InitializesthisPrimitiveBERTLVusing the input byte data.The capacity of
thisPrimitiveBERTLVis increased, if required and supported, to the byte length of the Value represented in the primitive TLV structure of the input byte array.Note:
- If
bOff+bLenis greater thanbArray.length, the length of thebArrayarray, anArrayIndexOutOfBoundsExceptionexception is thrown.
- Specified by:
initin classBERTLV- 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 primitive BER TLV structure.
- If
-
init
public short init(PrimitiveBERTag tag, byte[] vArray, short vOff, short vLen) throws TLVException
(Re-)InitializesthisPrimitiveBERTLVobject with the input tag, length and data. Note that a reference to the BER Tag object is retained bythisobject. A change in the BER Tag object contents affectsthisTLV instance.If
thisprimitive TLV object is empty, the initial capacity ofthisPrimitiveBERTLVis set to the value of the vLen argument.Note:
- If
vOff+vLenis greater thanvArray.length, the length of thevArrayarray, anArrayIndexOutOfBoundsExceptionexception is thrown.
- Parameters:
tag- aBERTagobjectvArray- the byte array containing length bytes of TLV valuevOff- offset within thevArraybyte array where data beginsvLen- byte length of the value data invArray- 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- if eithertagorvArrayparameter isnullTLVException- with the following reason codes:TLVException.INSUFFICIENT_STORAGEif the required capacity is not available and the implementation does not support automatic expansion.
- If
-
appendValue
public short appendValue(byte[] vArray, short vOff, short vLen) throws TLVExceptionAppends the specified data to the end ofthisPrimitive BER TLV object.Note:
- If
vOff+vLenis greater thanvArray.length, the length of thevArrayarray, anArrayIndexOutOfBoundsExceptionexception is thrown.
- Parameters:
vArray- the byte array containing length bytes of TLV valuevOff- offset within thevArraybyte array where data beginsvLen- the byte length of the value in the inputvArray- Returns:
- the resulting size of
thisif represented in bytes - Throws:
ArrayIndexOutOfBoundsException- if accessing the input array would cause access of data outside array bounds, or if the array offset or length parameter is negativeNullPointerException- ifvArrayisnullTLVException- with the following reason codes:TLVException.INSUFFICIENT_STORAGEif the required capacity is not available and the implementation does not support automatic expansionTLVException.EMPTY_TLVifthisPrimitiveBERTLVobject is empty.
- If
-
replaceValue
public short replaceValue(byte[] vArray, short vOff, short vLen) throws TLVExceptionReplaces the specified data in place of the current value ofthisPrimitive BER TLV object.Note:
- If
vOff+vLenis greater thanvArray.length, the length of thevArrayarray, anArrayIndexOutOfBoundsExceptionexception is thrown.
- Parameters:
vArray- the byte array containing length bytes of TLV valuevOff- offset within thevArraybyte array where data beginsvLen- the byte length of the value in the inputvArray- Returns:
- the resulting size of
thisif represented in bytes - Throws:
ArrayIndexOutOfBoundsException- if accessing the input array would cause access of data outside array bounds, or if the array offset or length parameter is negativeNullPointerException- ifvArrayisnullTLVException- with the following reason codes:TLVException.INSUFFICIENT_STORAGEif the required capacity is not available and the implementation does not support automatic expansionTLVException.EMPTY_TLVifthisPrimitiveBERTLVobject is empty.
- If
-
getValue
public short getValue(byte[] tlvValue, short tOff) throws TLVExceptionWrites the value (V) part ofthisPrimitive BER TLV object into the output buffer. Returns the length of data written to tlvValue output array- Parameters:
tlvValue- the output byte arraytOff- offset within thetlvValuebyte array where output data begins- Returns:
- the byte length of data written to tlvValue 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- iftlvValueisnullTLVException- with the following reason codes:TLVException.TLV_SIZE_GREATER_THAN_32767if the size of the Primitive BER TLV is > 32767TLVException.EMPTY_TLVifthisPrimitiveBERTLVobject is empty.
-
getValueOffset
public static short getValueOffset(byte[] berTLVArray, short bTLVOff) throws TLVExceptionReturns the offset into the specified input byte array of the value (V) part of the BER TLV structure representation in the input array.- Parameters:
berTLVArray- input byte arraybTLVOff- offset within byte array containing the TLV data- Returns:
- the offset into the specified input byte array of the value (V) part
- Throws:
ArrayIndexOutOfBoundsException- if accessing the input array would cause access of data outside array bounds, or if the array offset parameter is negativeNullPointerException- iftlvValueorberTLVArrayisnullTLVException- with the following reason codes:TLVException.TLV_SIZE_GREATER_THAN_32767if the size of the Primitive BER TLV is > 32767.TLVException.MALFORMED_TLVif the TLV representation in the input byte array is not a well-formed primitive BER TLV structure.
-
toBytes
public static short toBytes(byte[] berTagArray, short berTagOff, byte[] valueArray, short vOff, short vLen, byte[] outBuf, short bOff)Writes a primitive TLV representation to the specified byte array using as input a Primitive BER tag representation in a byte array and a value representation in another byte array.Note:
- If
vOff+vLenis greater thanvalueArray.length, the length of thevalueArrayarray, anArrayIndexOutOfBoundsExceptionexception is thrown.
- Parameters:
berTagArray- input byte arrayberTagOff- offset within byte array containing first byte of tagvalueArray- input byte array containing primitive valuevOff- offset within byte array containing the first byte of valuevLen- length in bytes of the value component of the TLVoutBuf- output byte arraybOff- offset within byte array output data begins- Returns:
- the byte length written to the output array
- Throws:
ArrayIndexOutOfBoundsException- if accessing the input or output arrays would cause access of data outside array bounds, or if any of the array offset or array length parameters is negativeNullPointerException- ifberTagArrayorvalueArrayoroutBufisnullTLVException- with the following reason codes:TLVException.TLV_SIZE_GREATER_THAN_32767if the size of the resulting Primitive BER TLV is > 32767.TLVException.MALFORMED_TAGif the tag representation in the byte array is not a well-formed constructed array tag.
- If
-
appendValue
public static short appendValue(byte[] berTLVArray, short bTLVOff, byte[] vArray, short vOff, short vLen) throws TLVExceptionAppends the specified data to the end of the Primitive TLV representation in the specified byte array. Note that this method is only applicable to a primitive TLV representation, otherwise an exception is thrown.Note:
- If
vOff+vLenis greater thanvArray.length, the length of thevArrayarray, anArrayIndexOutOfBoundsExceptionexception is thrown.
- Parameters:
berTLVArray- input byte arraybTLVOff- offset within byte array containing the TLV datavArray- the byte array containing value to be appendedvOff- offset within thevArraybyte array where the data beginsvLen- the byte length of the value in the inputvArray- Returns:
- the resulting size of
thisif represented in bytes - Throws:
ArrayIndexOutOfBoundsException- if accessing the input arrays would cause access of data outside array bounds, or if any of the array offset or array length parameters is negativeNullPointerException- ifberTLVArrayorvArrayisnullTLVException- with the following reason codes:TLVException.TLV_SIZE_GREATER_THAN_32767if the size of the resulting Primitive BER TLV is > 32767.TLVException.MALFORMED_TLVif the TLV representation in the input byte array is not a well-formed primitive BER TLV structure
- If
-
-