Enumerating numbersΒΆ

Some ASN.1 types such as Integer, Enumerated and BitString may enumerate their otherwise numeric values associating them with human-friendly labels.

class ErrorStatus(Integer):
"""
ASN.1 specification:

error-status
              INTEGER {
                  noError(0),
                  tooBig(1),
                  noSuchName(2),
                  ...
               }
"""
namedValues = NamedValues(
    ('noError', 0), ('tooBig', 1), ('noSuchName', 2)
)

The enumerated types behave exactly like the non-enumerated ones but, additionally, values can be referred by labels.

errorStatus = ErrorStatus('tooBig')

assert errorStatus == 1