Class ConstructedBERTLV
- java.lang.Object
-
- javacardx.framework.tlv.BERTLV
-
- javacardx.framework.tlv.ConstructedBERTLV
-
public final class ConstructedBERTLV extends BERTLV
TheConstructedBERTLVclass encapsulates a constructed BER TLV structure. It extends the generic BER TLV class. 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
ConstructedBERTLVclass 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 set of other BERTLVs.Every
ConstructedBERTLVhas a capacity which represents the size of the allocated internal data structures to reference all the contained BER TLV objects. As long as the number of contained BER TLV objects of theConstructedBERTLVdoes not exceed the capacity, it is not necessary to allocate new internal data. 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 a TLVException is thrown.The BERTLV class and the subclasses
ConstructedBERTLVandPrimitiveBERTLV, 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 ConstructedBERTLV(short numTLVs)Constructor creates an emptyConstructedBERTLVobject capable of encapsulating aConstructedBERTLVstructure.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static shortappend(byte[] berTLVInArray, short bTLVInOff, byte[] berTLVOutArray, short bTLVOutOff)Append the TLV representation in the specified byte array to the constructed BER tlv representation in the specified output byte array.shortappend(BERTLV aTLV)Append the specified TLV to the end ofConstructedBERTLV.shortdelete(BERTLV aTLV, short occurrenceNum)Delete the specified occurrence of the specified BER TLV fromthisConstructedBERTLV.static shortfind(byte[] berTLVArray, short bTLVOff, byte[] berTagArray, short bTagOff)Find the offset of the contained TLV representation at the top level within the TLV structure representation in the specified byte array that matches the specified tag representation in the specified byte array If the tag array parameter is null, the offset of the first contained TLV is returned.BERTLVfind(BERTag tag)Find the containedBERTLVwithinthisConstructedBERTLVobject that matches the specified BER Tag.static shortfindNext(byte[] berTLVArray, short bTLVOff, short startOffset, byte[] berTagArray, short bTagOff)Find the offset of the next contained TLV representation at the top level within the TLV structure representation in the specified byte array that matches the specified tag representation in the specified byte array.BERTLVfindNext(BERTag tag, BERTLV aTLV, short occurrenceNum)Find the next containedBERTLVwithinthisConstructedBERTLVobject that matches the specified BER Tag.shortinit(byte[] bArray, short bOff, short bLen)(Re-)InitializesthisConstructedBERTLVusing the input byte data.shortinit(ConstructedBERTag tag, byte[] vArray, short vOff, short vLen)(Re-)InitializesthisConstructedBERTLVobject with the input tag and specified data as value of the object.shortinit(ConstructedBERTag tag, BERTLV aTLV)(Re-)InitializesthisConstructedBERTLVobject with the input tag and TLV parameter.-
Methods inherited from class javacardx.framework.tlv.BERTLV
getInstance, getLength, getLength, getTag, getTag, size, toBytes, verifyFormat
-
-
-
-
Constructor Detail
-
ConstructedBERTLV
public ConstructedBERTLV(short numTLVs)
Constructor creates an emptyConstructedBERTLVobject capable of encapsulating aConstructedBERTLVstructure.The initial capacity is specified by the numTLVs argument.
- Parameters:
numTLVs- is the number of contained TLVs to allocate- Throws:
TLVException- with the following reason codes:TLVException.INVALID_PARAMif numTLVs 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-)InitializesthisConstructedBERTLVusing the input byte data.If
thisConstructedBERTLVis not empty, internal references to the previously contained BER TLV objects is removed.Each contained
BERTLVis constructed and initialized using this init method. The initial capacity of each of the containedConstructedBERTLVobjects is set to the number of TLVs contained at the top level of that TLV structure in the 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.ILLEGAL_SIZEif 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 constructed BER TLV structure.
- If
-
init
public short init(ConstructedBERTag tag, BERTLV aTLV) throws TLVException
(Re-)InitializesthisConstructedBERTLVobject with the input tag and TLV parameter. Note that a reference to the BER Tag object parameter is retained bythisobject. If the input BER Tag object is modified, the TLV structure encapsulated bythisTLV instance is also modified. Similarly, a reference to the BER TLV object parameter is also retained bythisobject. If the input BER TLV object is modified, the TLV structure encapsulated bythisTLV instance is also modified.- Parameters:
tag- aBERTagobjectaTLV- to use to initialize as the value ofthisTLV- Returns:
- the resulting size of
thisTLV if represented in bytes - Throws:
NullPointerException- if eithertagoraTLVisnullTLVException- with the following reason codes:TLVException.INSUFFICIENT_STORAGEif the required capacity is not available and the implementation does not support automatic expansionTLVException.INVALID_PARAMifaTLVisthisorthisTLV object is contained in any of the constructed TLV objects in the hierarchy of theaTLVobject.
-
init
public short init(ConstructedBERTag tag, byte[] vArray, short vOff, short vLen) throws TLVException
(Re-)InitializesthisConstructedBERTLVobject with the input tag and specified data as value of the object. Note that a reference to the BER Tag object is retained bythisobject. If the input BER Tag object is modified, the TLV structure encapsulated bythisTLV instance is also modified.Each contained
BERTLVis constructed and initialized using this init method. The initial capacity of each of the containedConstructedBERTLVobjects is set to the number of TLVs contained at the top level of that TLV structure in the byte array.Note:
- If
vOff+vLenis greater thanvArray.length, the length of thevArrayarray, anArrayIndexOutOfBoundsExceptionexception is thrown.
- Parameters:
tag- a BERTag objectvArray- the byte array containingvLenbytes of TLV ValuevOff- offset within the vArray byte array where data beginsvLen- byte length of the value data in vArray- 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 eithertagorvArrayisnullTLVException- with the following reason codes:TLVException.INSUFFICIENT_STORAGEor if the required capacity is not available and the implementation does not support automatic expansion.
- If
-
append
public short append(BERTLV aTLV) throws TLVException
Append the specified TLV to the end ofConstructedBERTLV. Note that a reference to the BER TLV object parameter is retained bythisobject. A change in the BER TLV object contents affectsthisTLV instance.- Parameters:
aTLV- a BER TLV object- Returns:
- the resulting size of
thisTLV if represented in bytes - Throws:
NullPointerException- ifaTLVisnullTLVException- with the following reason codes:TLVException.INSUFFICIENT_STORAGEif the required capacity is not available and the implementation does not support automatic expansion.TLVException.INVALID_PARAMifaTLVisthisorthisTLV object is contained in any of the constructed TLV objects in the hierarchy of theaTLVobject.
-
delete
public short delete(BERTLV aTLV, short occurrenceNum) throws TLVException
Delete the specified occurrence of the specified BER TLV fromthisConstructedBERTLV. The internal reference at the specified occurrence to the specified BER TLV object is removed.- Parameters:
aTLV- the BER TLV object to delete fromthisoccurrenceNum- specifies which occurrence ofaTLVwithinthisBER TLV to use- Returns:
- the resulting size of
thisTLV if represented in bytes - Throws:
NullPointerException- ifaTLVisnullTLVException- with the following reason codes:TLVException.INVALID_PARAMif the specified BER TLV object parameter is not an element ofthisor occurs less thanoccurrenceNumtimes inthisoroccurrenceNumis 0 or negative.
-
find
public BERTLV find(BERTag tag)
Find the containedBERTLVwithinthisConstructedBERTLVobject that matches the specified BER Tag. If the tag parameter isnull, the first contained BER TLV object is returned.- Parameters:
tag- theBERTagto be found- Returns:
- TLV object matching the indicated tag or null if none found.
-
findNext
public BERTLV findNext(BERTag tag, BERTLV aTLV, short occurrenceNum)
Find the next containedBERTLVwithinthisConstructedBERTLVobject that matches the specified BER Tag. The search must be started from the TLV position following the specified occurrence of the specified BER TLV object parameter. If the tag parameter is null, the next contained BER TLV object is returned.- Parameters:
tag- the BERTag to be foundaTLV- tlv object contained withinthisBER TLV following which the search beginsoccurrenceNum- specifies which occurrence ofaTLVwithinthisBER TLV to use- Returns:
- TLV object matching the indicated tag or null if none found.
- Throws:
NullPointerException- ifaTLVisnullTLVException- with the following reason codes:TLVException.INVALID_PARAMif the specified BER TLV object parameter is not an element ofthisor occurs less thanoccurrenceNumtimes inthisor ifoccurrenceNumis 0 or negative.
-
append
public static short append(byte[] berTLVInArray, short bTLVInOff, byte[] berTLVOutArray, short bTLVOutOff) throws TLVExceptionAppend the TLV representation in the specified byte array to the constructed BER tlv representation in the specified output byte array.- Parameters:
berTLVInArray- input byte arraybTLVInOff- offset within byte array containing the tlv databerTLVOutArray- output TLV byte arraybTLVOutOff- offset within byte array where output begins- Returns:
- the size of the resulting output TLV
- 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 eitherberTLVInArrayorberTLVOutArrayisnullTLVException- with the following reason codes:TLVException.MALFORMED_TLVif the TLV representation in the input byte array is not a well-formed constructed BER TLV.
-
find
public static short find(byte[] berTLVArray, short bTLVOff, byte[] berTagArray, short bTagOff) throws TLVExceptionFind the offset of the contained TLV representation at the top level within the TLV structure representation in the specified byte array that matches the specified tag representation in the specified byte array If the tag array parameter is null, the offset of the first contained TLV is returned.- Parameters:
berTLVArray- input byte arraybTLVOff- offset within byte array containing the tlv databerTagArray- byte array containing the Tag to be searchedbTagOff- offset withinberTagArraybyte array where tag data begins- Returns:
- offset into
berTLVArraywhere the indicated tag was found or -1 if none found. - Throws:
ArrayIndexOutOfBoundsException- if accessing the input arrays would cause access of data outside array bounds, or if either array offset parameter is negativeNullPointerException- ifberTLVArrayisnullTLVException- with the following reason codes:TLVException.MALFORMED_TLVif the TLV representation in the specified byte array is not a well-formed constructed BER TLV structure.TLVException.MALFORMED_TAGif tag representation in the specified byte array is is not a well-formed BER Tag structure.
-
findNext
public static short findNext(byte[] berTLVArray, short bTLVOff, short startOffset, byte[] berTagArray, short bTagOff) throws TLVExceptionFind the offset of the next contained TLV representation at the top level within the TLV structure representation in the specified byte array that matches the specified tag representation in the specified byte array. The search must be started from the TLV position following the specifiedstartOffsetparameter where a contained TLV exists at the top level. If the tag array parameter -berTagArray- is null, the offset of the next contained TLV representation at the top level is returned.- Parameters:
berTLVArray- input byte arraybTLVOff- offset within byte array containing the TLV datastartOffset- offset within the inputberTLVArrayto begin the searchberTagArray- byte array containing the Tag to be searchedbTagOff- offset withinberTagArraybyte array where tag data begins- Returns:
- offset into
berTLVArraywhere the indicated tag was found or -1 if none found. - Throws:
ArrayIndexOutOfBoundsException- if accessing the input arrays would cause access of data outside array bounds, or if any of the array offset parameters is negativeNullPointerException- ifberTLVArrayisnullTLVException- with the following reason codes:TLVException.MALFORMED_TLVif the TLV representation in the specified byte array is not a well-formed constructed BER TLV structure.TLVException.MALFORMED_TAGif the tag representation in the specified byte array is not a well-formed BER Tag structure.TLVException.INVALID_PARAMif theberTLVArrayarray does not contain a top level contained TLV element at the specifiedstartOffsetoffset.
-
-