NamedTypes

class pyasn1.type.namedtype.NamedTypes(*namedTypes)

Create a collection of named fields for a constructed ASN.1 type.

The NamedTypes object represents a collection of named fields of a constructed ASN.1 type.

NamedTypes objects are immutable and duck-type Python dict objects holding name as keys and ASN.1 type object as values.

Parameters:*namedTypes (NamedType)
getTypeByPosition(idx)

Return ASN.1 type object by its position in fields set.

Parameters:idx (int) – Field index
Returns:ASN.1 type
Raises:PyAsn1Error – If given position is out of fields range
getPositionByType(tagSet)

Return field position by its ASN.1 type.

Parameters:tagSet (TagSet) – ASN.1 tag set distinguishing one ASN.1 type from others.
Returns:int – ASN.1 type position in fields set
Raises:PyAsn1Error – If tagSet is not present or ASN.1 types are not unique within callee NamedTypes
getNameByPosition(idx)

Return field name by its position in fields set.

Parameters:idx (idx) – Field index
Returns:str – Field name
Raises:PyAsn1Error – If given field name is not present in callee NamedTypes
getPositionByName(name)

Return field position by filed name.

Parameters:name (str) – Field name
Returns:int – Field position in fields set
Raises:PyAsn1Error – If name is not present or not unique within callee NamedTypes
getTagMapNearPosition(idx)

Return ASN.1 types that are allowed at or past given field position.

Some ASN.1 serialization allow for skipping optional and defaulted fields. Some constructed ASN.1 types allow reordering of the fields. When recovering such objects it may be important to know which types can possibly be present at any given position in the field sets.

Parameters:idx (int) – Field index
Returns:TagMap – Map if ASN.1 types allowed at given field position
Raises:PyAsn1Error – If given position is out of fields range
getPositionNearType(tagSet, idx)

Return the closest field position where given ASN.1 type is allowed.

Some ASN.1 serialization allow for skipping optional and defaulted fields. Some constructed ASN.1 types allow reordering of the fields. When recovering such objects it may be important to know at which field position, in field set, given tagSet is allowed at or past idx position.

Parameters:
  • tagSet (TagSet) – ASN.1 type which field position to look up
  • idx (int) – Field position at or past which to perform ASN.1 type look up
Returns:

int – Field position in fields set

Raises:

PyAsn1Error – If tagSet is not present or not unique within callee NamedTypes or idx is out of fields range

minTagSet

Return the minimal TagSet among ASN.1 type in callee NamedTypes.

Some ASN.1 types/serialization protocols require ASN.1 types to be arranged based on their numerical tag value. The minTagSet property returns that.

Returns:TagSet – Minimal TagSet among ASN.1 types in callee NamedTypes
getTagMap(unique=False)

Create a TagMap object from tags and types recursively.

Create a new TagMap object by combining tags from TagMap objects of children types and associating them with their immediate child type.

Example

OuterType ::= CHOICE {
    innerType INTEGER
}

Calling .getTagMap() on OuterType will yield a map like this:

Integer.tagSet -> Choice
Parameters:unique (bool) – If True, duplicate TagSet objects occurring while building new TagMap would cause error.
Returns:TagMap – New TagMap holding TagSet object gathered from childen types.