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

ObjectIdentifier

ObjectIdentifier is a frozen (immutable, thread-safe) wrapper around an ASN.1 OBJECT IDENTIFIER value.

Constructors

ObjectIdentifier(oid_str: str)                     # from dotted-decimal, e.g. "2.5.4.3"
ObjectIdentifier.from_components(comps: list[int]) # from arc list
ObjectIdentifier.from_der_value(data: bytes)       # from implicit-tag content bytes (tag+length stripped)

Methods and dunders

Method / DunderReturnsDescription
components()tuple[int, ...]OID arc components
__str__()strDotted-decimal notation (cached)
__repr__()strObjectIdentifier('2.5.4.3')
__eq__(other)boolCompares against another ObjectIdentifier or a dotted str
__hash__()intConsistent with hash(str(oid)) so oid in {"2.5.4.3"} works

Full class stub

class ObjectIdentifier:
    def __init__(self, oid_str: str) -> None: ...
    @staticmethod
    def from_components(components: list[int]) -> ObjectIdentifier: ...
    def components(self) -> list[int]: ...
    def __str__(self) -> str: ...
    def __eq__(self, other: ObjectIdentifier) -> bool: ...
    def __hash__(self) -> int: ...

Working with Object Identifiers

import synta

# Create OID from dotted string
oid = synta.ObjectIdentifier("1.2.840.10045.2.1")
print(str(oid))  # Output: 1.2.840.10045.2.1

# Get components
components = oid.components()
print(components)  # Output: [1, 2, 840, 10045, 2, 1]

# Create OID from components
oid = synta.ObjectIdentifier.from_components([1, 2, 840, 10045, 4, 3, 2])
print(str(oid))  # Output: 1.2.840.10045.4.3.2

# Equality comparison against a string
import synta.oids as oids
assert oids.EC_PUBLIC_KEY == "1.2.840.10045.2.1"

# Use as a dict key (hashable)
lookup = {oids.SHA256: "SHA-256", oids.SHA384: "SHA-384"}
name = lookup.get(cert.signature_algorithm_oid, "unknown")

See also Well-known OIDs for the full OID constant catalog.