NamedTypes¶
- class pyasn1.type.namedtype.NamedTypes(*namedTypes, **kwargs)¶
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
)
Examples
class Description(Sequence): ''' ASN.1 specification: Description ::= SEQUENCE { surname IA5String, first-name IA5String OPTIONAL, age INTEGER DEFAULT 40 } ''' componentType = NamedTypes( NamedType('surname', IA5String()), OptionalNamedType('first-name', IA5String()), DefaultedNamedType('age', Integer(40)) ) descr = Description() descr['surname'] = 'Smith' descr['first-name'] = 'John'
Note
The NamedTypes objects are normally utilized by the constructed ASN.1 types (e.g. Sequence, Set and Choice) to model the set of fields of those types.
- 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 serialisation 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 serialisation 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
- 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
- property minTagSet¶
Return the minimal TagSet among ASN.1 type in callee NamedTypes.
Some ASN.1 types/serialisation 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
- property tagMap¶
Return a TagMap object from tags and types recursively.
Return a
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 .tagMap on OuterType will yield a map like this:
Integer.tagSet -> Choice
- property tagMapUnique¶
Return a TagMap object from unique tags and types recursively.
Return a
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 .tagMapUnique on OuterType will yield a map like this:
Integer.tagSet -> Choice
Note
Duplicate TagSet objects found in the tree of children types would cause error.