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
| Method | Returns | Description |
|---|---|---|
to_int() | int | Convert to Python int via i64; raises OverflowError if too large. |
to_i128() | int | Convert via i128; raises OverflowError if too large. |
to_bytes() | bytes | Raw 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
| Method | Returns |
|---|---|
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
| Method | Returns | Description |
|---|---|---|
value() | float | |
is_infinite() | bool | True for ±∞ |
is_nan() | bool | True for NaN |
is_finite() | bool | True for finite, non-NaN |
__float__() | float | Enables float(r) |
__eq__, __hash__ | Hash consistent with IEEE 754 (NaN != NaN, -0.0 == 0.0) |
Special values (X.690 encoding)
| Value | DER bytes |
|---|---|
0.0 | 09 00 |
math.inf | 09 01 40 |
-math.inf | 09 01 41 |
math.nan | 09 01 42 |
finite f64 | 09 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