Table of Contents

Class TlvObjects

Namespace
Yubico.Core.Tlv
Assembly
Yubico.Core.dll

Utility methods to encode and decode BER-TLV data.

public static class TlvObjects
Inheritance
object
TlvObjects

Methods

DecodeDictionary(ReadOnlySpan<byte>)

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.

public static IReadOnlyDictionary<int, ReadOnlyMemory<byte>> DecodeDictionary(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

Sequence of TLV encoded data

Returns

IReadOnlyDictionary<int, ReadOnlyMemory<byte>>

Dictionary of Tag-Value pairs

DecodeList(ReadOnlySpan<byte>)

Decodes a sequence of BER-TLV encoded data into a list of Tlvs.

public static IReadOnlyList<TlvObject> DecodeList(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

Sequence of TLV encoded data

Returns

IReadOnlyList<TlvObject>

List of TlvObject

EncodeDictionary(IReadOnlyDictionary<int, byte[]>)

public static Memory<byte> EncodeDictionary(IReadOnlyDictionary<int, byte[]> map)

Parameters

map IReadOnlyDictionary<int, byte[]>

Returns

Memory<byte>

EncodeList(IEnumerable<TlvObject>)

Encodes a list of Tlvs into a sequence of BER-TLV encoded data.

public static byte[] EncodeList(IEnumerable<TlvObject> list)

Parameters

list IEnumerable<TlvObject>

List of Tlvs to encode

Returns

byte[]

BER-TLV encoded list

EncodeMany(params TlvObject[])

Encodes an array of Tlvs into a sequence of BER-TLV encoded data.

public static byte[] EncodeMany(params TlvObject[] tlvs)

Parameters

tlvs TlvObject[]

Array of Tlvs to encode

Returns

byte[]

BER-TLV encoded array

UnpackValue(int, ReadOnlySpan<byte>)

Decode a single TLV encoded object, returning only the value.

public static Memory<byte> UnpackValue(int expectedTag, ReadOnlySpan<byte> tlvData)

Parameters

expectedTag int

The expected tag value of the given TLV data

tlvData ReadOnlySpan<byte>

The TLV data

Returns

Memory<byte>

The value of the TLV

Exceptions

InvalidOperationException

If the TLV tag differs from expectedTag