Package com.yubico.yubikit.core.util
Class Tlvs
java.lang.Object
com.yubico.yubikit.core.util.Tlvs
public class Tlvs
extends java.lang.Object
Utility methods to encode and decode BER-TLV data.
-
Constructor Summary
Constructors Constructor Description Tlvs()
-
Method Summary
Modifier and Type Method Description static java.util.List<Tlv>
decodeList(byte[] data)
Decodes a sequence of BER-TLV encoded data into a list of Tlvs.static java.util.Map<java.lang.Integer,byte[]>
decodeMap(byte[] data)
Decodes a sequence of BER-TLV encoded data into a mapping of Tag-Value pairs.static byte[]
encodeList(java.lang.Iterable<? extends Tlv> list)
Encodes a List of Tlvs into an array of bytes.static byte[]
encodeMap(java.util.Map<java.lang.Integer,byte[]> map)
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
public static java.util.Map<java.lang.Integer,byte[]> decodeMap(byte[] data)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
public static byte[] encodeMap(java.util.Map<java.lang.Integer,byte[]> map)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
-