diff options
author | Brian Wellington <bwelling@xbill.org> | 2020-07-09 09:52:05 -0700 |
---|---|---|
committer | Brian Wellington <bwelling@xbill.org> | 2020-07-09 09:52:05 -0700 |
commit | 033349257b72cb7bf5d65a536051bbe14b80e141 (patch) | |
tree | 46753a2f1368e395feb944dca423b7288c8fa6d2 | |
parent | 6070cffcadf72508c19e60cd6d4d24601c1ea7aa (diff) | |
download | dnspython-033349257b72cb7bf5d65a536051bbe14b80e141.tar.gz |
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.
-rw-r--r-- | dns/rdata.py | 2 | ||||
-rw-r--r-- | dns/rdtypes/ANY/TSIG.py | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/dns/rdata.py b/dns/rdata.py index 64d2024..fd9bea9 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 0d4b48b..18db4c9 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) |