Package com.yubico.yubikit.core.util
Class Tlvs
java.lang.Object
com.yubico.yubikit.core.util.Tlvs
Utility methods to encode and decode BER-TLV data.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecodeList
(byte[] data) Decodes a sequence of BER-TLV encoded data into a list of Tlvs.decodeMap
(byte[] data) Decodes a sequence of BER-TLV encoded data into a mapping of Tag-Value pairs.static byte[]
encodeList
(Iterable<? extends Tlv> list) Encodes a List of Tlvs into an array of bytes.static byte[]
Encodes a Map of Tag-Value pairs into an array of bytes.static byte[]
unpackValue
(int expectedTag, byte[] tlvData) Decode a single TLV encoded object, returning only the value.
-
Constructor Details
-
Tlvs
public Tlvs()
-
-
Method Details
-
decodeList
Decodes a sequence of BER-TLV encoded data into a list of Tlvs.- Parameters:
data
- sequence of TLV encoded data- Returns:
- list of Tlvs
-
decodeMap
Decodes a sequence of BER-TLV encoded data into a mapping of Tag-Value pairs.Iteration order is preserved. If the same tag occurs more than once only the latest will be kept.
- Parameters:
data
- sequence of TLV encoded data- Returns:
- map of Tag-Value pairs
-
encodeList
Encodes a List of Tlvs into an array of bytes.- Parameters:
list
- list of Tlvs- Returns:
- the data encoded as a sequence of TLV values
-
encodeMap
Encodes a Map of Tag-Value pairs into an array of bytes. NOTE: If order is important use a Map implementation that preserves order, such as LinkedHashMap.- Parameters:
map
- the tag-value mappings- Returns:
- the data encoded as a sequence of TLV values
-
unpackValue
Decode a single TLV encoded object, returning only the value.- Parameters:
expectedTag
- the expected tag value of the given TLV datatlvData
- the TLV data- Returns:
- the value of the TLV
- Throws:
BadResponseException
- if the TLV tag differs from expectedTag
-