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

Bit and Octet Strings

OctetString

ASN.1 tag 0x04.

Constructor

OctetString(data: bytes)

Methods

MethodReturns
to_bytes()bytes
__len__()int
__eq__(other)bool

Full class stub

class OctetString:
    def __init__(self, data: bytes) -> None: ...
    def to_bytes(self) -> bytes: ...
    def __len__(self) -> int: ...
    def __eq__(self, other: OctetString) -> bool: ...

BitString

ASN.1 tag 0x03.

Constructor

BitString(data: bytes, unused_bits: int)   # unused_bits in 0–7

Methods

MethodReturnsDescription
to_bytes()bytesRaw content bytes (excluding unused-bits octet).
unused_bits()intNumber of padding bits in the last byte.
bit_len()intTotal significant bits (len(data) * 8 - unused_bits).
__len__()intSame as bit_len().
__eq__(other)bool

Full class stub

class BitString:
    def __init__(self, data: bytes, unused_bits: int) -> None: ...
    def to_bytes(self) -> bytes: ...
    def unused_bits(self) -> int: ...
    def bit_len(self) -> int: ...
    def __len__(self) -> int: ...         # byte length (same as len(to_bytes()))
    def __eq__(self, other: BitString) -> bool: ...