]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Add next_name() method to NSEC3 [#1022].
authorBob Halley <halley@dnspython.org>
Sun, 17 Dec 2023 01:51:01 +0000 (17:51 -0800)
committerBob Halley <halley@dnspython.org>
Sun, 17 Dec 2023 01:51:01 +0000 (17:51 -0800)
dns/rdtypes/ANY/NSEC3.py
tests/test_rdata.py

index d32fe169fe92dd5b2869e6edb2e3864a1eb09b53..a02f8e7701248c740a6573687c177ac07d912013 100644 (file)
@@ -64,9 +64,13 @@ class NSEC3(dns.rdata.Rdata):
             windows = Bitmap(windows)
         self.windows = tuple(windows.windows)
 
-    def to_text(self, origin=None, relativize=True, **kw):
+    def _next_text(self):
         next = base64.b32encode(self.next).translate(b32_normal_to_hex).lower().decode()
         next = next.rstrip("=")
+        return next
+
+    def to_text(self, origin=None, relativize=True, **kw):
+        next = self._next_text()
         if self.salt == b"":
             salt = "-"
         else:
@@ -118,3 +122,6 @@ class NSEC3(dns.rdata.Rdata):
         next = parser.get_counted_bytes()
         bitmap = Bitmap.from_wire_parser(parser)
         return cls(rdclass, rdtype, algorithm, flags, iterations, salt, next, bitmap)
+
+    def next_name(self, origin=None):
+        return dns.name.from_text(self._next_text(), origin)
index b9cfea8edf2d071332dd84d3264a6ae32558391f..cb8ae519c695d03dbe96d5bbe12fef5a28307c37 100644 (file)
@@ -22,26 +22,24 @@ import pickle
 import struct
 import unittest
 
-import dns.wire
 import dns.exception
 import dns.name
 import dns.rdata
 import dns.rdataclass
 import dns.rdataset
 import dns.rdatatype
-from dns.rdtypes.ANY.OPT import OPT
-from dns.rdtypes.ANY.LOC import LOC
-from dns.rdtypes.ANY.GPOS import GPOS
 import dns.rdtypes.ANY.RRSIG
 import dns.rdtypes.IN.APL
 import dns.rdtypes.util
 import dns.tokenizer
 import dns.ttl
 import dns.wire
-
+import tests.md_module
 import tests.stxt_module
 import tests.ttxt_module
-import tests.md_module
+from dns.rdtypes.ANY.GPOS import GPOS
+from dns.rdtypes.ANY.LOC import LOC
+from dns.rdtypes.ANY.OPT import OPT
 from tests.util import here
 
 
@@ -838,6 +836,20 @@ class RdataTestCase(unittest.TestCase):
         finally:
             dns.rdata._allow_relative_comparisons = saved
 
+    def test_nsec3_next_name(self):
+        rdata = dns.rdata.from_text(
+            "in",
+            "nsec3",
+            "1 1 0 - CK0Q2D6NI4I7EQH8NA30NS61O48UL8G5 NS SOA RRSIG DNSKEY NSEC3PARAM",
+        )
+        origin = dns.name.from_text("com")
+        expected_rel = dns.name.from_text(
+            "ck0q2d6ni4i7eqh8na30ns61o48ul8g5", origin=None
+        )
+        expected_abs = dns.name.from_text("ck0q2d6ni4i7eqh8na30ns61o48ul8g5.com.")
+        self.assertEqual(rdata.next_name(), expected_rel)
+        self.assertEqual(rdata.next_name(origin), expected_abs)
+
 
 class UtilTestCase(unittest.TestCase):
     def test_Gateway_bad_type0(self):