Skip to content

Commit

Permalink
Add next_name() method to NSEC3 [#1022].
Browse files Browse the repository at this point in the history
  • Loading branch information
rthalley committed Dec 17, 2023
1 parent 9c81b6d commit 18fa8c4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
9 changes: 8 additions & 1 deletion dns/rdtypes/ANY/NSEC3.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ def __init__(
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:
Expand Down Expand Up @@ -118,3 +122,6 @@ def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
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)
24 changes: 18 additions & 6 deletions tests/test_rdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,24 @@
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


Expand Down Expand Up @@ -838,6 +836,20 @@ def bad4():
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):
Expand Down

0 comments on commit 18fa8c4

Please sign in to comment.