tlv

package
v0.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Overview

Package tlv implements various version (ASN.1 BER, Simple, Compact) TLV encoding using in ISO 7816-4.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTag   = errors.New("invalid tag")
	ErrTagToBig     = errors.New("tag is too big for this encoding")
	ErrValueToLarge = errors.New("valye to large for this encoding")
)
View Source
var ErrNotConstructed = errors.New("tag is not constructed but contains children")

Functions

func EncodeBER

func EncodeBER(tvs ...TagValue) (buf []byte, err error)

func EncodeCompact

func EncodeCompact(tvs ...TagValue) (buf []byte, err error)

func EncodeLengthBER added in v0.4.0

func EncodeLengthBER(l int) ([]byte, error)

func EncodeSimple

func EncodeSimple(tvs ...TagValue) (buf []byte, err error)

Types

type Class

type Class byte
const (
	ClassUniversal   Class = 0b00
	ClassApplication Class = 0b01
	ClassContext     Class = 0b10
	ClassPrivate     Class = 0b11
)

type Tag

type Tag uint // In theory ISO 7816-4 also supports 3-byte tags

func NewBERTag added in v0.8.1

func NewBERTag(number uint, class Class) Tag

NewBERTag creates a new ASN.1 BER-TLV encoded tag field from a value and class. See: ISO 7816-4 Section 5.2.2.1 BER-TLV tag fields

func (Tag) BERNumber added in v0.8.1

func (t Tag) BERNumber() uint

BERNumber returns the BER-encoded number of the tag.

func (Tag) Class

func (t Tag) Class() Class

Class returns the class of the tag.

func (Tag) IsConstructed

func (t Tag) IsConstructed() bool

IsConstructed returns true if the tag is constructed.

func (Tag) MarshalBER added in v0.3.0

func (t Tag) MarshalBER() (buf []byte, err error)

MarshalBER returns a BER-encoded representation of the tag.

func (*Tag) UnmarshalBER added in v0.3.0

func (t *Tag) UnmarshalBER(buf []byte) (rBuf []byte, err error)

UnmarshalBER decodes an ASN.1 BER-TLV encoded tag field. See: ISO 7816-4 Section 5.2.2.1 BER-TLV tag fields

type TagValue

type TagValue struct {
	Tag        Tag
	Value      []byte
	Children   TagValues
	SkipLength bool
}

func New

func New(t Tag, values ...any) (tv TagValue)

func (*TagValue) Append added in v0.4.0

func (tv *TagValue) Append(value any)

func (TagValue) Equal added in v0.2.0

func (tv TagValue) Equal(w TagValue) bool

func (TagValue) MarshalBER

func (tv TagValue) MarshalBER() (buf []byte, err error)

MarshalBER encodes an ASN.1 BER-TLV encoded tag field. See: ISO 7816-4 Section 5.2.2.1 BER-TLV tag fields

func (*TagValue) UnmarshalBER

func (tv *TagValue) UnmarshalBER(buf []byte) ([]byte, error)

type TagValues added in v0.2.0

type TagValues []TagValue

func DecodeBER

func DecodeBER(buf []byte) (tvs TagValues, err error)

func DecodeCompact

func DecodeCompact(buf []byte) (tvs TagValues, err error)

func DecodeSimple

func DecodeSimple(buf []byte) (tvs TagValues, err error)

func (*TagValues) DeleteAll added in v0.2.0

func (tvs *TagValues) DeleteAll(tag Tag) (removed int)

func (TagValues) Equal added in v0.2.0

func (tvs TagValues) Equal(w TagValues) bool

func (TagValues) Get added in v0.2.0

func (tvs TagValues) Get(tag Tag) ([]byte, TagValues, bool)

func (*TagValues) GetAll added in v0.2.0

func (tvs *TagValues) GetAll(tag Tag) (s TagValues)

func (TagValues) GetChild added in v0.2.0

func (tvs TagValues) GetChild(tag Tag, subs ...Tag) ([]byte, TagValues, bool)

func (*TagValues) Pop added in v0.2.0

func (tvs *TagValues) Pop(tag Tag) (TagValue, bool)

func (*TagValues) PopAll added in v0.2.0

func (tvs *TagValues) PopAll(tag Tag) (s TagValues)

func (*TagValues) Put added in v0.2.0

func (tvs *TagValues) Put(tv TagValue)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL