]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Make dns.rdata._base64ify(..., 0) work.
authorBrian Wellington <bwelling@xbill.org>
Thu, 9 Jul 2020 16:52:05 +0000 (09:52 -0700)
committerBrian Wellington <bwelling@xbill.org>
Thu, 9 Jul 2020 16:52:05 +0000 (09:52 -0700)
In some cases, the caller absolutely doesn't want word breaks.  This
shouldn't be the case for any normal DNS record, but is for records that
don't have well-defined text formats, like TSIG and TKEY.  Allow them to
pass 0 (or None), to indicate that no word breaks should be added.

Previously, passing either 0 or None resulted in an exception, as the
value was used directly as the step in a slice.

dns/rdata.py
dns/rdtypes/ANY/TSIG.py

index 64d20245d8c3c12ae9dd5a71808a9c1841c7abc6..fd9bea99712ebb114dbfa943d5dfc474eafd1497 100644 (file)
@@ -53,6 +53,8 @@ def _base64ify(data, chunksize=_base64_chunksize):
     """
 
     line = base64.b64encode(data)
+    if not chunksize:
+        return line
     return b' '.join([line[i:i + chunksize]
                       for i
                       in range(0, len(line), chunksize)]).decode()
index 0d4b48b6bda45ead9c7b5e30375e2db64ca44d3e..18db4c9e0ea9d32b88f6626e6691d752ebc4e836 100644 (file)
@@ -63,9 +63,9 @@ class TSIG(dns.rdata.Rdata):
     def to_text(self, origin=None, relativize=True, **kw):
         algorithm = self.algorithm.choose_relativity(origin, relativize)
         return f"{algorithm} {self.fudge} {self.time_signed} " + \
-               f"{len(self.mac)} {dns.rdata._base64ify(self.mac, 256)} " + \
+               f"{len(self.mac)} {dns.rdata._base64ify(self.mac, 0)} " + \
                f"{self.original_id} {self.error} " + \
-               f"{len(self.other)} {dns.rdata._base64ify(self.other, 256)}"
+               f"{len(self.other)} {dns.rdata._base64ify(self.other, 0)}"
 
     def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
         self.algorithm.to_wire(file, None, origin, False)