Package org.eclipse.keyple.core.util
Class BerTlvUtil
java.lang.Object
org.eclipse.keyple.core.util.BerTlvUtil
Helper class to decode BER-TLV encoded data.
This class offers a tradeoff between complexity and efficiency adapted to the TLV structures encountered in smart card data, it has the following limitations:
- The tag ID fields must not exceed 3 bytes.
- The length fields must not exceed 3 bytes.
- Tags present several times in the same TLV structure require special attention (see
parseSimple(byte[], boolean)
).
- Since:
- 2.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isConstructed
(int tagId) Indicates if the provided tag ID corresponds to a constructed tag.parse
(byte[] tlvStructure, boolean primitiveOnly) Parse the provided TLV structure and place all or only primitive tags found in a map.parseSimple
(byte[] tlvStructure, boolean primitiveOnly) Parse the provided TLV structure and place all or only primitive tags found in a map.
-
Method Details
-
parseSimple
Parse the provided TLV structure and place all or only primitive tags found in a map. The key is an integer representing the tag ID (e.g. 0x84 for the DF name tag), the value is the tag value as an array of bytes.Note:This method of extracting tags is deliberately simplified.
If the provided TLV structure contains several identical tags then only one will be reported in the returned map.
To overcome this limitation it is recommended to re-parse the constructed tags known to contain other tags.- Parameters:
tlvStructure
- The input TLV structure.primitiveOnly
- True if only primitives tags are to be placed in the map.- Returns:
- A not null map.
- Throws:
IllegalArgumentException
- If the parsing of the provided structure failed.- Since:
- 2.0.0
-
parse
Parse the provided TLV structure and place all or only primitive tags found in a map. The key is an integer representing the tag ID (e.g. 0x84 for the DF name tag), the value is the list of tag values as a list of arrays of bytes.- Parameters:
tlvStructure
- The input TLV structure.primitiveOnly
- True if only primitives tags are to be placed in the map.- Returns:
- A not null map.
- Throws:
IllegalArgumentException
- If the parsing of the provided structure failed.- Since:
- 2.1.0
-
isConstructed
public static boolean isConstructed(int tagId) Indicates if the provided tag ID corresponds to a constructed tag.- Parameters:
tagId
- A positive int less than FFFFFFh.- Returns:
- True if the tag is constructed.
- Throws:
IllegalArgumentException
- If the tag ID is out of range.- Since:
- 2.0.0
-