Class Tlvs

java.lang.Object
com.yubico.yubikit.core.util.Tlvs

public class Tlvs extends Object
Utility methods to encode and decode BER-TLV data.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<Tlv>
    decodeList(byte[] data)
    Decodes a sequence of BER-TLV encoded data into a list of Tlvs.
    static Map<Integer,byte[]>
    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[]
    encodeMap(Map<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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Tlvs

      public Tlvs()
  • Method Details

    • decodeList

      public static List<Tlv> decodeList(byte[] data)
      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 Map<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

      public static byte[] encodeList(Iterable<? extends Tlv> list)
      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(Map<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

      public static byte[] unpackValue(int expectedTag, byte[] tlvData) throws BadResponseException
      Decode a single TLV encoded object, returning only the value.
      Parameters:
      expectedTag - the expected tag value of the given TLV data
      tlvData - the TLV data
      Returns:
      the value of the TLV
      Throws:
      BadResponseException - if the TLV tag differs from expectedTag