Tag set

class pyasn1.type.tag.TagSet(baseTag=(), *superTags)

Create a collection of ASN.1 tags

Represents a combination of Tag objects that can be attached to a ASN.1 type to make types distinguishable from each other.

TagSet objects are immutable and duck-type Python tuple objects holding arbitrary number of Tag objects.

Parameters
  • baseTag (Tag) – Base Tag object. This tag survives IMPLICIT tagging.

  • *superTags (Tag) – Additional Tag objects taking part in subtyping.

Examples

class OrderNumber(NumericString):
    '''
    ASN.1 specification

    Order-number ::=
        [APPLICATION 5] IMPLICIT NumericString
    '''
    tagSet = NumericString.tagSet.tagImplicitly(
        Tag(tagClassApplication, tagFormatSimple, 5)
    )

orderNumber = OrderNumber('1234')

Note

The TagSet objects are normally used by all ASN.1 type objects both simple (like Integer) and constructed (e.g. Sequence).

property baseTag

Return base ASN.1 tag

Returns

Tag – Base tag of this TagSet

property superTags

Return ASN.1 tags

Returns

tuple – Tuple of Tag objects that this TagSet contains

tagExplicitly(superTag)

Return explicitly tagged TagSet

Create a new TagSet representing callee TagSet explicitly tagged with passed tag(s). With explicit tagging mode, new tags are appended to existing tag(s).

Parameters

superTag (Tag) – Tag object to tag this TagSet

Returns

TagSet – New TagSet object

tagImplicitly(superTag)

Return implicitly tagged TagSet

Create a new TagSet representing callee TagSet implicitly tagged with passed tag(s). With implicit tagging mode, new tag(s) replace the last existing tag.

Parameters

superTag (Tag) – Tag object to tag this TagSet

Returns

TagSet – New TagSet object

isSuperTagSetOf(tagSet)

Test type relationship against given TagSet

The callee is considered to be a supertype of given TagSet tag-wise if all tags in TagSet are present in the callee and they are in the same order.

Parameters

tagSet (TagSet) – TagSet object to evaluate against the callee

Returns

boolTrue if callee is a supertype of tagSet