]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Move algorithm definitions into a top-level isctest.algorithms module
authorNicki Křížek <nicki@isc.org>
Tue, 16 Jun 2026 16:23:23 +0000 (16:23 +0000)
committerNicki Křížek <nicki@isc.org>
Thu, 2 Jul 2026 12:51:41 +0000 (14:51 +0200)
The Algorithm type, the per-algorithm constants, and the ALL_ALGORITHMS*
lookup tables are general DNSSEC key definitions used across isctest
package and the tests. Move them into a dedicated module to separate
these from the environment-specific setup that remains in
isctest.vars.algorithms.

Assisted-by: Claude:claude-opus-4-8
17 files changed:
bin/tests/system/conftest.py
bin/tests/system/dnssec_py/tests_mixed_ds.py
bin/tests/system/isctest/__init__.py
bin/tests/system/isctest/algorithms.py [new file with mode: 0644]
bin/tests/system/isctest/kasp.py
bin/tests/system/isctest/vars/algorithms.py
bin/tests/system/isctest/zone.py
bin/tests/system/kasp/tests_kasp.py
bin/tests/system/ksr/tests_ksr.py
bin/tests/system/migrate2kasp/tests_migrate2kasp.py
bin/tests/system/nsec3/tests_nsec3_change.py
bin/tests/system/nsec3/tests_nsec3_initial.py
bin/tests/system/nsec3/tests_nsec3_reconfig.py
bin/tests/system/nsec3/tests_nsec3_restart.py
bin/tests/system/nsec3/tests_nsec3_retransfer.py
bin/tests/system/rollover/setup.py
bin/tests/system/rollover/tests_rollover_manual.py

index b9a4943be9cd6237b6254ef3105360821649a3aa..e0c2a08d660573ec0b6f04d412b86c2476549bff 100644 (file)
@@ -273,7 +273,7 @@ def control_port():
 
 @pytest.fixture(scope="module")
 def default_algorithm():
-    return isctest.vars.algorithms.Algorithm.default()
+    return isctest.algorithms.Algorithm.default()
 
 
 @pytest.fixture(scope="module")
index a3c9d43845a429fcb0d98c5f3ba8c1ba90266e7d..57ca84457f50e0f84fe9ac309beaa8a8439c6350 100644 (file)
@@ -12,8 +12,8 @@
 from re import compile as Re
 
 from dnssec_py.common import DNSSEC_PY_MARK
+from isctest.algorithms import Algorithm
 from isctest.template import NS2, NS3, zones
-from isctest.vars.algorithms import Algorithm
 from isctest.zone import Zone, configure_root
 
 import isctest
index 30256087b302967d7219fbac90518fff8393300a..326b77f0d4e82d4e717f1c1385db3c6c81c109a7 100644 (file)
@@ -10,6 +10,7 @@
 # information regarding copyright ownership.
 
 from . import (  # pylint: disable=redefined-builtin
+    algorithms,
     check,
     hypothesis,
     instance,
@@ -29,6 +30,7 @@ from . import (  # pylint: disable=redefined-builtin
 # instead.
 
 __all__ = [
+    "algorithms",
     "check",
     "hypothesis",
     "instance",
diff --git a/bin/tests/system/isctest/algorithms.py b/bin/tests/system/isctest/algorithms.py
new file mode 100644 (file)
index 0000000..160282f
--- /dev/null
@@ -0,0 +1,61 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0.  If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+from typing import NamedTuple
+
+import os
+
+
+class Algorithm(NamedTuple):
+    name: str
+    number: int
+    dst: int
+    bits: int
+
+    @classmethod
+    def default(cls):
+        return cls(
+            os.environ["DEFAULT_ALGORITHM"],
+            int(os.environ["DEFAULT_ALGORITHM_NUMBER"]),
+            int(os.environ["DEFAULT_ALGORITHM_DST_NUMBER"]),
+            int(os.environ["DEFAULT_BITS"]),
+        )
+
+
+RSASHA1 = Algorithm("RSASHA1", 5, 5, 2048)
+NSEC3RSASHA1 = Algorithm("NSEC3RSASHA1", 7, 7, 2048)
+RSASHA256 = Algorithm("RSASHA256", 8, 8, 2048)
+RSASHA512 = Algorithm("RSASHA512", 10, 10, 2048)
+ECDSAP256SHA256 = Algorithm("ECDSAP256SHA256", 13, 13, 256)
+ECDSAP384SHA384 = Algorithm("ECDSAP384SHA384", 14, 14, 384)
+ED25519 = Algorithm("ED25519", 15, 15, 256)
+ED448 = Algorithm("ED448", 16, 16, 456)
+RSASHA256OID = Algorithm("RSASHA256OID", 254, 256, 2048)
+RSASHA512OID = Algorithm("RSASHA512OID", 254, 257, 2048)
+
+ALL_ALGORITHMS = [
+    RSASHA1,
+    NSEC3RSASHA1,
+    RSASHA256,
+    RSASHA512,
+    ECDSAP256SHA256,
+    ECDSAP384SHA384,
+    ED25519,
+    ED448,
+    RSASHA256OID,
+    RSASHA512OID,
+]
+
+ALL_ALGORITHMS_BY_NUM = {alg.number: alg for alg in ALL_ALGORITHMS}
+# Keyed by the DST identifier rather than the on-wire number: unlike `number`
+# (where both private-OID variants collide at 254), `dst` is unique, so this
+# map distinguishes RSASHA256OID (256) from RSASHA512OID (257).
+ALL_ALGORITHMS_BY_DST = {alg.dst: alg for alg in ALL_ALGORITHMS}
index 2c82cce37b5648e96f957e983f1e6be3358aba2b..0bc7bd9b4be920c410f52b57b89cca3e8c27fb84 100644 (file)
@@ -29,9 +29,9 @@ import dns.rdatatype
 import dns.tsig
 import dns.zone
 
+from isctest.algorithms import ALL_ALGORITHMS_BY_DST, ECDSAP256SHA256, Algorithm
 from isctest.instance import NamedInstance
 from isctest.run import EnvCmd
-from isctest.vars.algorithms import ALL_ALGORITHMS_BY_DST, ECDSAP256SHA256, Algorithm
 from isctest.zone import FileZoneKey
 
 import isctest.log
index a0081e0c47c1c67be3ad95a4a78f202ff7f39e6d..61c8097f711f85330defb28ed41ca2d114774739 100644 (file)
@@ -19,6 +19,16 @@ import tempfile
 import time
 
 from .. import log
+from ..algorithms import (
+    ALL_ALGORITHMS,
+    ECDSAP256SHA256,
+    ECDSAP384SHA384,
+    ED448,
+    ED25519,
+    RSASHA256,
+    RSASHA512,
+    Algorithm,
+)
 from .basic import BASIC_VARS
 
 # Algorithms are selected randomly at runtime from a list of supported
@@ -55,22 +65,6 @@ STABLE_PERIOD = 3600 * 3
 """number of secs during which algorithm selection remains stable"""
 
 
-class Algorithm(NamedTuple):
-    name: str
-    number: int
-    dst: int
-    bits: int
-
-    @classmethod
-    def default(cls):
-        return cls(
-            os.environ["DEFAULT_ALGORITHM"],
-            int(os.environ["DEFAULT_ALGORITHM_NUMBER"]),
-            int(os.environ["DEFAULT_ALGORITHM_DST_NUMBER"]),
-            int(os.environ["DEFAULT_BITS"]),
-        )
-
-
 class AlgorithmSet(NamedTuple):
     """Collection of DEFAULT, ALTERNATIVE and DISABLED algorithms"""
 
@@ -86,36 +80,6 @@ class AlgorithmSet(NamedTuple):
     "disable-algorithms" configuration option."""
 
 
-RSASHA1 = Algorithm("RSASHA1", 5, 5, 2048)
-NSEC3RSASHA1 = Algorithm("NSEC3RSASHA1", 7, 7, 2048)
-RSASHA256 = Algorithm("RSASHA256", 8, 8, 2048)
-RSASHA512 = Algorithm("RSASHA512", 10, 10, 2048)
-ECDSAP256SHA256 = Algorithm("ECDSAP256SHA256", 13, 13, 256)
-ECDSAP384SHA384 = Algorithm("ECDSAP384SHA384", 14, 14, 384)
-ED25519 = Algorithm("ED25519", 15, 15, 256)
-ED448 = Algorithm("ED448", 16, 16, 456)
-RSASHA256OID = Algorithm("RSASHA256OID", 254, 256, 2048)
-RSASHA512OID = Algorithm("RSASHA512OID", 254, 257, 2048)
-
-ALL_ALGORITHMS = [
-    RSASHA1,
-    NSEC3RSASHA1,
-    RSASHA256,
-    RSASHA512,
-    ECDSAP256SHA256,
-    ECDSAP384SHA384,
-    ED25519,
-    ED448,
-    RSASHA256OID,
-    RSASHA512OID,
-]
-
-ALL_ALGORITHMS_BY_NUM = {alg.number: alg for alg in ALL_ALGORITHMS}
-# Keyed by the DST identifier rather than the on-wire number: unlike `number`
-# (where both private-OID variants collide at 254), `dst` is unique, so this
-# map distinguishes RSASHA256OID (256) from RSASHA512OID (257).
-ALL_ALGORITHMS_BY_DST = {alg.dst: alg for alg in ALL_ALGORITHMS}
-
 ALGORITHM_SETS = {
     "stable": AlgorithmSet(
         default=ECDSAP256SHA256, alternative=RSASHA256, disabled=ECDSAP384SHA384
index 8f5a88662778e72d0dfa7e12a87771a12f1d7858..359d0f270743654fbea7c1527c8f492b2c4612fc 100644 (file)
@@ -30,10 +30,7 @@ import dns.rdatatype
 import dns.rrset
 import dns.zonefile
 
-from .log import debug
-from .run import EnvCmd
-from .template import NS1, Nameserver, TemplateEngine, TrustAnchor
-from .vars.algorithms import (
+from .algorithms import (
     ALL_ALGORITHMS_BY_NUM,
     ECDSAP256SHA256,
     ECDSAP384SHA384,
@@ -41,6 +38,9 @@ from .vars.algorithms import (
     ED25519,
     Algorithm,
 )
+from .log import debug
+from .run import EnvCmd
+from .template import NS1, Nameserver, TemplateEngine, TrustAnchor
 
 KEYDIR = "keys"
 DNSKEY_TTL = 3600
index 5f970a66be1bbed09bc52a3ac8866928ba1cd904..c57807e940cb246e20a7f6996d7b3fb88d84fafa 100644 (file)
@@ -25,9 +25,9 @@ import dns.tsig
 import dns.update
 import pytest
 
+from isctest.algorithms import ECDSAP256SHA256, ECDSAP384SHA384, Algorithm
 from isctest.kasp import KeyProperties, KeyTimingMetadata, SettimeOptions
 from isctest.util import param
-from isctest.vars.algorithms import ECDSAP256SHA256, ECDSAP384SHA384, Algorithm
 
 import isctest
 import isctest.mark
index b1e1be907eb7f9fed15c894f213ed720e54f7c82..5f54a3361f016da7c92171f5b3efd7523fdcacc2 100644 (file)
@@ -18,8 +18,8 @@ import time
 
 import pytest
 
+from isctest.algorithms import Algorithm
 from isctest.kasp import KeyTimingMetadata
-from isctest.vars.algorithms import Algorithm
 from rollover.common import TIMEDELTA
 
 import isctest
index 3e4150ee7f684f08cee05fe0787a598581bfcc76..750eee509b5f4f0733f917601c55b9ae42aba698 100644 (file)
@@ -15,7 +15,7 @@ import os
 
 import pytest
 
-from isctest.vars.algorithms import Algorithm
+from isctest.algorithms import Algorithm
 
 import isctest
 
index b8a8b066e36988a4c40eb39e6a22f22e7659fe21..564a670d6373afcd438d333937ae30d7b174096b 100644 (file)
@@ -17,7 +17,7 @@ import dns.rdataclass
 import dns.rdatatype
 import pytest
 
-from isctest.vars.algorithms import Algorithm
+from isctest.algorithms import Algorithm
 from nsec3.common import NSEC3_MARK, check_nsec3_case
 
 import isctest
index d855032bd131c39fa17a79bd69fb8a79fbf9b889..8fb23ee2a2f4d3a4ec9ac0fc160d4680ddaa0f38 100644 (file)
@@ -17,7 +17,7 @@ import dns.rcode
 import dns.update
 import pytest
 
-from isctest.vars.algorithms import RSASHA1, Algorithm
+from isctest.algorithms import RSASHA1, Algorithm
 from nsec3.common import NSEC3_MARK, check_nsec3_case
 
 import isctest
index 1a4ba812f0b94ba83544fa7d4ed3739171548bc0..ea3ee8e843a8171be3283bde4e48e04803de99e4 100644 (file)
@@ -18,7 +18,7 @@ import dns.rdataclass
 import dns.rdatatype
 import pytest
 
-from isctest.vars.algorithms import RSASHA1, Algorithm
+from isctest.algorithms import RSASHA1, Algorithm
 from nsec3.common import NSEC3_MARK, check_nsec3_case
 
 import isctest
index ca6ebef8118e5fca8ddf6a05a139c130f104126c..aed7c417812f1c6e269bc15ab056dc8747b8c5a2 100644 (file)
@@ -14,7 +14,7 @@ import os
 import dns.rdatatype
 import pytest
 
-from isctest.vars.algorithms import Algorithm
+from isctest.algorithms import Algorithm
 from nsec3.common import NSEC3_MARK, check_nsec3_case, check_nsec3param
 
 import isctest
index 4df768cc00feefb594436a69ed6f0d36ae04be41..bb019d395fbc1a41ed5b28232a7454671e550e87 100644 (file)
@@ -16,7 +16,7 @@ import os
 import dns.rcode
 import dns.rdatatype
 
-from isctest.vars.algorithms import RSASHA256
+from isctest.algorithms import RSASHA256
 from nsec3.common import NSEC3_MARK, check_auth_nsec3, check_nsec3param
 
 import isctest
index dc83402069dcd7920bc54702b7a827c76acc463c..97bed7e1e8844399aece1eb127272fe872546244 100644 (file)
@@ -13,10 +13,10 @@ from pathlib import Path
 
 import shutil
 
+from isctest.algorithms import Algorithm
 from isctest.kasp import SettimeOptions, private_type_record
 from isctest.run import EnvCmd
 from isctest.template import NS2, NS3, TrustAnchor, Zone
-from isctest.vars.algorithms import Algorithm
 
 import isctest
 
index 71907a0be5354f609306b5fae9d0ec9e12891b1d..d7e326db9c246c8bb2cc099e1fa622338244687c 100644 (file)
@@ -11,6 +11,7 @@
 
 from datetime import timedelta
 
+from isctest.algorithms import Algorithm
 from isctest.kasp import (
     Ipub,
     Iret,
@@ -20,7 +21,6 @@ from isctest.kasp import (
 )
 from isctest.run import EnvCmd
 from isctest.template import NS3, Zone
-from isctest.vars.algorithms import Algorithm
 from rollover.setup import configure_root, configure_tld, setkeytimes
 
 import isctest