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,
)
| 86 | |
| 87 | |
| 88 | def 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 |
searching dependent graphs…