From: Bob Halley Date: Sun, 17 Dec 2023 01:51:01 +0000 (-0800) Subject: Add next_name() method to NSEC3 [#1022]. X-Git-Tag: v2.5.0rc1~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18fa8c43e92bb5452eab88c3ac72f46c9b795a51;p=thirdparty%2Fdnspython.git Add next_name() method to NSEC3 [#1022]. --- diff --git a/dns/rdtypes/ANY/NSEC3.py b/dns/rdtypes/ANY/NSEC3.py index d32fe169..a02f8e77 100644 --- a/dns/rdtypes/ANY/NSEC3.py +++ b/dns/rdtypes/ANY/NSEC3.py @@ -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) diff --git a/tests/test_rdata.py b/tests/test_rdata.py index b9cfea8e..cb8ae519 100644 --- a/tests/test_rdata.py +++ b/tests/test_rdata.py @@ -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):