MCPcopy Create free account
hub / github.com/rthalley/dnspython / register_algorithm_cls

Function register_algorithm_cls

dns/dnssecalgs/__init__.py:88–124  ·  view source on GitHub ↗

Register Algorithm Private Key class. *algorithm*, a ``str`` or ``int`` specifying the DNSKEY algorithm. *algorithm_cls*: A `GenericPrivateKey` class. *name*, an optional ``dns.name.Name`` or ``str``, for for PRIVATEDNS algorithms. *oid*: an optional BER-encoded `bytes` for PRIVA

(
    algorithm: int | str,
    algorithm_cls: Type[GenericPrivateKey],
    name: dns.name.Name | str | None = None,
    oid: bytes | None = None,
)

Source from the content-addressed store, hash-verified

86
87
88def register_algorithm_cls(
89 algorithm: int | str,
90 algorithm_cls: Type[GenericPrivateKey],
91 name: dns.name.Name | str | None = None,
92 oid: bytes | None = None,
93) -> None:
94 """Register Algorithm Private Key class.
95
96 *algorithm*, a ``str`` or ``int`` specifying the DNSKEY algorithm.
97
98 *algorithm_cls*: A `GenericPrivateKey` class.
99
100 *name*, an optional ``dns.name.Name`` or ``str``, for for PRIVATEDNS algorithms.
101
102 *oid*: an optional BER-encoded `bytes` for PRIVATEOID algorithms.
103
104 Raises ``ValueError`` if a name or oid is specified incorrectly.
105 """
106 if not issubclass(algorithm_cls, GenericPrivateKey):
107 raise TypeError("Invalid algorithm class")
108 algorithm = Algorithm.make(algorithm)
109 prefix: AlgorithmPrefix = None
110 if algorithm == Algorithm.PRIVATEDNS:
111 if name is None:
112 raise ValueError("Name required for PRIVATEDNS algorithms")
113 if isinstance(name, str):
114 name = dns.name.from_text(name)
115 prefix = name
116 elif algorithm == Algorithm.PRIVATEOID:
117 if oid is None:
118 raise ValueError("OID required for PRIVATEOID algorithms")
119 prefix = bytes([len(oid)]) + oid
120 elif name:
121 raise ValueError("Name only supported for PRIVATEDNS algorithm")
122 elif oid:
123 raise ValueError("OID only supported for PRIVATEOID algorithm")
124 algorithms[(algorithm, prefix)] = algorithm_cls

Callers 4

test_privateMethod · 0.90
test_registerMethod · 0.90

Calls 2

makeMethod · 0.45
from_textMethod · 0.45

Tested by 4

test_privateMethod · 0.72
test_registerMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…