OpenType

class pyasn1.type.opentype.OpenType(name, typeMap=None)

Create ASN.1 type map indexed by a value

The DefinedBy object models the ASN.1 DEFINED BY clause which maps values to ASN.1 types in the context of the ASN.1 SEQUENCE/SET type.

OpenType objects are duck-type a read-only Python dict objects, however the passed typeMap is stored by reference.

Parameters:
  • name (str) – Field name
  • typeMap (dict) – A map of value->ASN.1 type. It’s stored by reference and can be mutated later to register new mappings.

Examples

openType = OpenType(
    'id',
    {1: Integer(),
     2: OctetString()}
)
Sequence(
    componentType=NamedTypes(
        NamedType('id', Integer()),
        NamedType('blob', Any(), openType=openType)
    )
)

Note

The OpenType class models an untyped field of a constructed ASN.1 type. In ASN.1 syntax it is usually represented by the ANY DEFINED BY clause. Typically used with Any type.