From: Brian Wellington Date: Thu, 9 Jul 2020 16:52:05 +0000 (-0700) Subject: Make dns.rdata._base64ify(..., 0) work. X-Git-Tag: v2.0.0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=033349257b72cb7bf5d65a536051bbe14b80e141;p=thirdparty%2Fdnspython.git Make dns.rdata._base64ify(..., 0) work. 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. --- diff --git a/dns/rdata.py b/dns/rdata.py index 64d20245..fd9bea99 100644 --- a/dns/rdata.py +++ b/dns/rdata.py @@ -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() diff --git a/dns/rdtypes/ANY/TSIG.py b/dns/rdtypes/ANY/TSIG.py index 0d4b48b6..18db4c9e 100644 --- a/dns/rdtypes/ANY/TSIG.py +++ b/dns/rdtypes/ANY/TSIG.py @@ -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)