INTEGER

An ASN.1 INTEGER assignment results in the creation of a Python class in the following cases:

In these cases, a class is generated that contains static encode and decode methods. For encode, the method first checks the value to make sure it is within the bounds of the constraint and then calls the encode_integer function within the base encoding rules library. For decode, the decode_integer function is first called to decode the value and then the value checked against the constraints to determine if it is within the defined range.

In the case of named numbers, tables are generated to map the actual integer values to their numeric equivalents. These allow an integer value to be represented as a string or integer value. If string, the string value is looked up in the table prior to encode. If integer, it is encoded directly. On decode, the decode integer value is looked up in the table to see if it has a named identifier. If it does, the identifier string value is returned; otherwise the integer value.

Example ASN.1:

I ::= INTEGER (1..10)

Generated Python Class:

class I:
    @staticmethod
    def ber_decode(decbuf, explicit=True, impllen=None):
    ...

    @staticmethod
    def ber_encode(value, encbuf, explicit=True):
    ...

The value that is returned by the decode method or passed into the encode method may be an integer numeric value, or, in the case of named numbers, may be the string representation of the number.

See the BER encode/decode methods for information on how to call these methods.