Tag

class bertlv.tag.TagClass(value)[source]

Bases: enum.Enum

An enumeration.

UNIVERSAL = 0
APPLICATION = 1
CONTEXT_SPECIFIC = 2
PRIVATE = 3
class bertlv.tag.TagType(value)[source]

Bases: enum.Enum

An enumeration.

PRIMITIVE = 0
CONSTRUCTED = 1
class bertlv.tag.Tag(identifier: bytes, *, force_constructed: bool = False)[source]

Bases: object

This represents a TLV tag following the BER encoding.

It consists of the following parts: - Tag class: bits 7-8 of the initial octet - Tag type: bit 6 of the initial octet - Tag number: bits 1-5 of the initial octet and bits 1-7 of subsequent octets

CLASS_BITMASK = 192
TYPE_BITMASK = 32
property identifier

Return the identifier octets of this tag.

property tag_class

Return the class of this tag.

property tag_type

Return the type of this tag.

xml_tag()str[source]
is_constructed()bool[source]

Return true if the tag is constructed otherwise false.

to_int()int[source]

Return an integer representing a tag.

to_hex()str[source]

Return a hex string representing a tag.

to_xml(element: xml.etree.ElementTree.Element)xml.etree.ElementTree.Element[source]

Return an XML element representing a tag.

classmethod from_int(tag: int, *, force_constructed: bool = False)bertlv.tag.Tag[source]

Return the tag represented by the given integer.

classmethod from_hex(tag: str, *, force_constructed: bool = False)bertlv.tag.Tag[source]

Return the tag represented by the given hex string.

class bertlv.tag.RootTag[source]

Bases: bertlv.tag.Tag