Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Numeric Types: Integer, Real, Boolean, Null

Integer

ASN.1 tag 0x02.

Constructors

Integer(value: int)            # constructor — i64 range only
Integer.from_bytes(data: bytes) -> Integer   # big-endian two's complement
Integer.from_u64(value: int) -> Integer      # unsigned 64-bit

Methods

MethodReturnsDescription
to_int()intConvert to Python int via i64; raises OverflowError if too large.
to_i128()intConvert via i128; raises OverflowError if too large.
to_bytes()bytesRaw big-endian two’s complement bytes.

Special methods: __repr__, __str__, __eq__, __hash__.

Full class stub

class Integer:
    def __init__(self, value: int) -> None: ...
    def to_int(self) -> int: ...          # Raises OverflowError if > i64
    def to_i128(self) -> int: ...         # Raises OverflowError if > i128
    def to_bytes(self) -> bytes: ...      # Big-endian two's complement
    @staticmethod
    def from_bytes(data: bytes) -> Integer: ...
    @staticmethod
    def from_u64(value: int) -> Integer: ...
    def __eq__(self, other: object) -> bool: ...    # Compares canonical DER encoding
    def __hash__(self) -> int: ...                  # Hash over canonical DER bytes

Boolean

ASN.1 tag 0x01.

Constructors

Boolean(value: bool)

Methods

MethodReturns
value()bool
__bool__()bool

Full class stub

class Boolean:
    def __init__(self, value: bool) -> None: ...
    def value(self) -> bool: ...
    def __bool__(self) -> bool: ...
    def __eq__(self, other: object) -> bool: ...
    def __hash__(self) -> int: ...   # hash(True) == 1, hash(False) == 0

Real

ASN.1 tag 0x09.

Constructors

Real(value: float)

Methods

MethodReturnsDescription
value()float
is_infinite()boolTrue for ±∞
is_nan()boolTrue for NaN
is_finite()boolTrue for finite, non-NaN
__float__()floatEnables float(r)
__eq__, __hash__Hash consistent with IEEE 754 (NaN != NaN, -0.0 == 0.0)

Special values (X.690 encoding)

ValueDER bytes
0.009 00
math.inf09 01 40
-math.inf09 01 41
math.nan09 01 42
finite f6409 09 80 <8 bytes>

Full class stub

class Real:
    def __init__(self, value: float) -> None: ...
    def value(self) -> float: ...
    def is_infinite(self) -> bool: ...   # True for +∞ and −∞
    def is_nan(self) -> bool: ...
    def is_finite(self) -> bool: ...
    def __float__(self) -> float: ...
    def __eq__(self, other: Real) -> bool: ...  # NaN != NaN (IEEE 754)
    def __hash__(self) -> int: ...              # -0.0 normalised to 0.0 before hashing

Null

ASN.1 tag 0x05.

Null()

__repr__ returns "Null()". All Null() instances compare equal.

Full class stub

class Null:
    def __init__(self) -> None: ...
    def __eq__(self, other: object) -> bool: ...  # Always True for Null instances
    def __hash__(self) -> int: ...                 # Always 0