Table of Contents

Class TlvObject

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

Tag, length, Value structure that helps to parse APDU response data. This class handles BER-TLV encoded data with determinate length.

public sealed class TlvObject
Inheritance
object
TlvObject

Constructors

TlvObject(int, ReadOnlySpan<byte>)

Creates a new TLV (Tag-Length-Value) object with the specified tag and value.

public TlvObject(int tag, ReadOnlySpan<byte> value)

Parameters

tag int

The tag value, must be between 0x00 and 0xFFFF.

value ReadOnlySpan<byte>

The value data as a read-only span of bytes.

Remarks

This constructor creates a BER-TLV encoded structure where:

  • The tag is encoded in the minimum number of bytes needed
  • The length is encoded according to BER-TLV rules
  • The value is stored as provided

Exceptions

TlvException

Thrown when the tag value is outside the supported range (0x00-0xFFFF).

Properties

Length

Returns the length of the value.

public int Length { get; }

Property Value

int

Tag

Returns the tag.

public int Tag { get; }

Property Value

int

Value

Returns a copy of the value.

public Memory<byte> Value { get; }

Property Value

Memory<byte>

Methods

Dispose()

Dispose the object and clears its buffers

public void Dispose()

GetBytes()

Returns a copy of the Tlv as a BER-TLV encoded byte array.

public Memory<byte> GetBytes()

Returns

Memory<byte>

Parse(ReadOnlySpan<byte>)

Parse a Tlv from a BER-TLV encoded byte array.

public static TlvObject Parse(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

A byte array containing the TLV encoded data (and nothing more).

Returns

TlvObject

The parsed Tlv

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

Remarks

The string is of the form Tlv(0xTAG, LENGTH, VALUE).

The tag is written out in hexadecimal, prefixed by 0x. The length is written out in decimal. The value is written out in hexadecimal.

TryParse(ReadOnlySpan<byte>, out TlvObject?)

Parse a Tlv from a BER-TLV encoded byte array.

public static bool TryParse(ReadOnlySpan<byte> data, out TlvObject? tlvObject)

Parameters

data ReadOnlySpan<byte>

A byte array containing the TLV encoded data (and nothing more).

tlvObject TlvObject

Returns

bool

The parsed Tlv