From: Bob Halley Date: Thu, 4 Sep 2014 22:21:32 +0000 (-0700) Subject: All rdata comparsion now uses the digestable form. X-Git-Tag: v1.13.0~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43c14fd73b3b94211ff8bfad8f894b48cce4e577;p=thirdparty%2Fdnspython.git All rdata comparsion now uses the digestable form. --- diff --git a/ChangeLog b/ChangeLog index cb2bb450..c953588e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2014-09-04 Bob Halley + * Comparing two rdata is now always done by comparing the binary + data of the DNSSEC digestable forms. This corrects a number of + errors where dnspython's rdata comparsion order was not the + DNSSEC order. + * Add CAA implementation. Thanks to Brian Wellington for the patch. diff --git a/dns/rdata.py b/dns/rdata.py index 350bf790..3a31ae1c 100644 --- a/dns/rdata.py +++ b/dns/rdata.py @@ -207,8 +207,8 @@ class Rdata(object): rdclass. Return < 0 if self < other in the DNSSEC ordering, 0 if self == other, and > 0 if self > other. """ - - raise NotImplementedError + return cmp(self.to_digestable(dns.name.root), + other.to_digestable(dns.name.root)) def __eq__(self, other): if not isinstance(other, Rdata): @@ -257,19 +257,6 @@ class Rdata(object): def __hash__(self): return hash(self.to_digestable(dns.name.root)) - def _wire_cmp(self, other): - # A number of types compare rdata in wire form, so we provide - # the method here instead of duplicating it. - # - # We specifiy an arbitrary origin of '.' when doing the - # comparison, since the rdata may have relative names and we - # can't convert a relative name to wire without an origin. - b1 = cStringIO.StringIO() - self.to_wire(b1, None, dns.name.root) - b2 = cStringIO.StringIO() - other.to_wire(b2, None, dns.name.root) - return cmp(b1.getvalue(), b2.getvalue()) - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): """Build an rdata object from text format. @@ -363,9 +350,6 @@ class GenericRdata(Rdata): from_wire = classmethod(from_wire) - def _cmp(self, other): - return cmp(self.data, other.data) - _rdata_modules = {} _module_prefix = 'dns.rdtypes' diff --git a/dns/rdtypes/ANY/CAA.py b/dns/rdtypes/ANY/CAA.py index 34a042f5..3bd52a09 100644 --- a/dns/rdtypes/ANY/CAA.py +++ b/dns/rdtypes/ANY/CAA.py @@ -71,13 +71,3 @@ class CAA(dns.rdata.Rdata): return cls(rdclass, rdtype, flags, tag, value) from_wire = classmethod(from_wire) - - def _cmp(self, other): - v = cmp(self.flags, other.flags) - if v == 0: - v = cmp(len(self.tag), len(other.tag)) - if v == 0: - v = cmp(self.tag, other.tag) - if v == 0: - v = cmp(self.value, other.value) - return v diff --git a/dns/rdtypes/ANY/CERT.py b/dns/rdtypes/ANY/CERT.py index c102521a..df2ab07b 100644 --- a/dns/rdtypes/ANY/CERT.py +++ b/dns/rdtypes/ANY/CERT.py @@ -117,15 +117,3 @@ class CERT(dns.rdata.Rdata): certificate) from_wire = classmethod(from_wire) - - def _cmp(self, other): - f = cStringIO.StringIO() - self.to_wire(f) - wire1 = f.getvalue() - f.seek(0) - f.truncate() - other.to_wire(f) - wire2 = f.getvalue() - f.close() - - return cmp(wire1, wire2) diff --git a/dns/rdtypes/ANY/DNSKEY.py b/dns/rdtypes/ANY/DNSKEY.py index 7bc58500..cb059337 100644 --- a/dns/rdtypes/ANY/DNSKEY.py +++ b/dns/rdtypes/ANY/DNSKEY.py @@ -128,14 +128,6 @@ class DNSKEY(dns.rdata.Rdata): from_wire = classmethod(from_wire) - def _cmp(self, other): - hs = struct.pack("!HBB", self.flags, self.protocol, self.algorithm) - ho = struct.pack("!HBB", other.flags, other.protocol, other.algorithm) - v = cmp(hs, ho) - if v == 0: - v = cmp(self.key, other.key) - return v - def flags_to_text_set(self): """Convert a DNSKEY flags value to set texts @rtype: set([string])""" diff --git a/dns/rdtypes/ANY/GPOS.py b/dns/rdtypes/ANY/GPOS.py index 38d1d88b..39994811 100644 --- a/dns/rdtypes/ANY/GPOS.py +++ b/dns/rdtypes/ANY/GPOS.py @@ -120,14 +120,6 @@ class GPOS(dns.rdata.Rdata): from_wire = classmethod(from_wire) - def _cmp(self, other): - v = cmp(self.latitude, other.latitude) - if v == 0: - v = cmp(self.longitude, other.longitude) - if v == 0: - v = cmp(self.altitude, other.altitude) - return v - def _get_float_latitude(self): return float(self.latitude) diff --git a/dns/rdtypes/ANY/HINFO.py b/dns/rdtypes/ANY/HINFO.py index 15fd54e6..4fe7a0f9 100644 --- a/dns/rdtypes/ANY/HINFO.py +++ b/dns/rdtypes/ANY/HINFO.py @@ -75,9 +75,3 @@ class HINFO(dns.rdata.Rdata): return cls(rdclass, rdtype, cpu, os) from_wire = classmethod(from_wire) - - def _cmp(self, other): - v = cmp(self.cpu, other.cpu) - if v == 0: - v = cmp(self.os, other.os) - return v diff --git a/dns/rdtypes/ANY/HIP.py b/dns/rdtypes/ANY/HIP.py index 968b36f5..654d5c79 100644 --- a/dns/rdtypes/ANY/HIP.py +++ b/dns/rdtypes/ANY/HIP.py @@ -111,30 +111,3 @@ class HIP(dns.rdata.Rdata): server = server.choose_relativity(origin, relativize) servers.append(server) self.servers = servers - - def _cmp(self, other): - b1 = cStringIO.StringIO() - lh = len(self.hit) - lk = len(self.key) - b1.write(struct.pack("!BBH", lh, self.algorithm, lk)) - b1.write(self.hit) - b1.write(self.key) - b2 = cStringIO.StringIO() - lh = len(other.hit) - lk = len(other.key) - b2.write(struct.pack("!BBH", lh, other.algorithm, lk)) - b2.write(other.hit) - b2.write(other.key) - v = cmp(b1.getvalue(), b2.getvalue()) - if v != 0: - return v - ls = len(self.servers) - lo = len(other.servers) - count = min(ls, lo) - i = 0 - while i < count: - v = cmp(self.servers[i], other.servers[i]) - if v != 0: - return v - i += 1 - return ls - lo diff --git a/dns/rdtypes/ANY/ISDN.py b/dns/rdtypes/ANY/ISDN.py index 0c2d3cd0..0a5c01d5 100644 --- a/dns/rdtypes/ANY/ISDN.py +++ b/dns/rdtypes/ANY/ISDN.py @@ -88,9 +88,3 @@ class ISDN(dns.rdata.Rdata): return cls(rdclass, rdtype, address, subaddress) from_wire = classmethod(from_wire) - - def _cmp(self, other): - v = cmp(self.address, other.address) - if v == 0: - v = cmp(self.subaddress, other.subaddress) - return v diff --git a/dns/rdtypes/ANY/LOC.py b/dns/rdtypes/ANY/LOC.py index 6266ae66..6cc55217 100644 --- a/dns/rdtypes/ANY/LOC.py +++ b/dns/rdtypes/ANY/LOC.py @@ -313,18 +313,6 @@ class LOC(dns.rdata.Rdata): from_wire = classmethod(from_wire) - def _cmp(self, other): - f = cStringIO.StringIO() - self.to_wire(f) - wire1 = f.getvalue() - f.seek(0) - f.truncate() - other.to_wire(f) - wire2 = f.getvalue() - f.close() - - return cmp(wire1, wire2) - def _get_float_latitude(self): return _tuple_to_float(self.latitude) diff --git a/dns/rdtypes/ANY/NSEC.py b/dns/rdtypes/ANY/NSEC.py index ad113a4b..fd76cc43 100644 --- a/dns/rdtypes/ANY/NSEC.py +++ b/dns/rdtypes/ANY/NSEC.py @@ -123,6 +123,3 @@ class NSEC(dns.rdata.Rdata): def choose_relativity(self, origin = None, relativize = True): self.next = self.next.choose_relativity(origin, relativize) - - def _cmp(self, other): - return self._wire_cmp(other) diff --git a/dns/rdtypes/ANY/NSEC3.py b/dns/rdtypes/ANY/NSEC3.py index b42fe4c8..1ed391dc 100644 --- a/dns/rdtypes/ANY/NSEC3.py +++ b/dns/rdtypes/ANY/NSEC3.py @@ -175,10 +175,3 @@ class NSEC3(dns.rdata.Rdata): return cls(rdclass, rdtype, algorithm, flags, iterations, salt, next, windows) from_wire = classmethod(from_wire) - - def _cmp(self, other): - b1 = cStringIO.StringIO() - self.to_wire(b1) - b2 = cStringIO.StringIO() - other.to_wire(b2) - return cmp(b1.getvalue(), b2.getvalue()) diff --git a/dns/rdtypes/ANY/NSEC3PARAM.py b/dns/rdtypes/ANY/NSEC3PARAM.py index f514991a..e12b04fc 100644 --- a/dns/rdtypes/ANY/NSEC3PARAM.py +++ b/dns/rdtypes/ANY/NSEC3PARAM.py @@ -80,10 +80,3 @@ class NSEC3PARAM(dns.rdata.Rdata): return cls(rdclass, rdtype, algorithm, flags, iterations, salt) from_wire = classmethod(from_wire) - - def _cmp(self, other): - b1 = cStringIO.StringIO() - self.to_wire(b1) - b2 = cStringIO.StringIO() - other.to_wire(b2) - return cmp(b1.getvalue(), b2.getvalue()) diff --git a/dns/rdtypes/ANY/RP.py b/dns/rdtypes/ANY/RP.py index 26c55314..cb6b7c8d 100644 --- a/dns/rdtypes/ANY/RP.py +++ b/dns/rdtypes/ANY/RP.py @@ -78,9 +78,3 @@ class RP(dns.rdata.Rdata): def choose_relativity(self, origin = None, relativize = True): self.mbox = self.mbox.choose_relativity(origin, relativize) self.txt = self.txt.choose_relativity(origin, relativize) - - def _cmp(self, other): - v = cmp(self.mbox, other.mbox) - if v == 0: - v = cmp(self.txt, other.txt) - return v diff --git a/dns/rdtypes/ANY/RRSIG.py b/dns/rdtypes/ANY/RRSIG.py index 98c548df..77ce2bfd 100644 --- a/dns/rdtypes/ANY/RRSIG.py +++ b/dns/rdtypes/ANY/RRSIG.py @@ -150,6 +150,3 @@ class RRSIG(dns.rdata.Rdata): def choose_relativity(self, origin = None, relativize = True): self.signer = self.signer.choose_relativity(origin, relativize) - - def _cmp(self, other): - return self._wire_cmp(other) diff --git a/dns/rdtypes/ANY/SOA.py b/dns/rdtypes/ANY/SOA.py index 2d6f21b5..de786147 100644 --- a/dns/rdtypes/ANY/SOA.py +++ b/dns/rdtypes/ANY/SOA.py @@ -112,16 +112,3 @@ class SOA(dns.rdata.Rdata): def choose_relativity(self, origin = None, relativize = True): self.mname = self.mname.choose_relativity(origin, relativize) self.rname = self.rname.choose_relativity(origin, relativize) - - def _cmp(self, other): - v = cmp(self.mname, other.mname) - if v == 0: - v = cmp(self.rname, other.rname) - if v == 0: - self_ints = struct.pack('!IIIII', self.serial, self.refresh, - self.retry, self.expire, self.minimum) - other_ints = struct.pack('!IIIII', other.serial, other.refresh, - other.retry, other.expire, - other.minimum) - v = cmp(self_ints, other_ints) - return v diff --git a/dns/rdtypes/ANY/SSHFP.py b/dns/rdtypes/ANY/SSHFP.py index 4c439511..f5a34c21 100644 --- a/dns/rdtypes/ANY/SSHFP.py +++ b/dns/rdtypes/ANY/SSHFP.py @@ -74,11 +74,3 @@ class SSHFP(dns.rdata.Rdata): return cls(rdclass, rdtype, header[0], header[1], fingerprint) from_wire = classmethod(from_wire) - - def _cmp(self, other): - hs = struct.pack("!BB", self.algorithm, self.fp_type) - ho = struct.pack("!BB", other.algorithm, other.fp_type) - v = cmp(hs, ho) - if v == 0: - v = cmp(self.fingerprint, other.fingerprint) - return v diff --git a/dns/rdtypes/ANY/TLSA.py b/dns/rdtypes/ANY/TLSA.py index 6ca8c0a5..92867ef3 100644 --- a/dns/rdtypes/ANY/TLSA.py +++ b/dns/rdtypes/ANY/TLSA.py @@ -79,11 +79,3 @@ class TLSA(dns.rdata.Rdata): return cls(rdclass, rdtype, header[0], header[1], header[2], cert) from_wire = classmethod(from_wire) - - def _cmp(self, other): - hs = struct.pack("!BBB", self.usage, self.selector, self.mtype) - ho = struct.pack("!BBB", other.usage, other.selector, other.mtype) - v = cmp(hs, ho) - if v == 0: - v = cmp(self.cert, other.cert) - return v diff --git a/dns/rdtypes/ANY/X25.py b/dns/rdtypes/ANY/X25.py index ae91295f..47671e4d 100644 --- a/dns/rdtypes/ANY/X25.py +++ b/dns/rdtypes/ANY/X25.py @@ -57,6 +57,3 @@ class X25(dns.rdata.Rdata): return cls(rdclass, rdtype, address) from_wire = classmethod(from_wire) - - def _cmp(self, other): - return cmp(self.address, other.address) diff --git a/dns/rdtypes/IN/A.py b/dns/rdtypes/IN/A.py index 372d3332..945d9348 100644 --- a/dns/rdtypes/IN/A.py +++ b/dns/rdtypes/IN/A.py @@ -50,8 +50,3 @@ class A(dns.rdata.Rdata): return cls(rdclass, rdtype, address) from_wire = classmethod(from_wire) - - def _cmp(self, other): - sa = dns.ipv4.inet_aton(self.address) - oa = dns.ipv4.inet_aton(other.address) - return cmp(sa, oa) diff --git a/dns/rdtypes/IN/AAAA.py b/dns/rdtypes/IN/AAAA.py index e131bd50..65be1c25 100644 --- a/dns/rdtypes/IN/AAAA.py +++ b/dns/rdtypes/IN/AAAA.py @@ -51,8 +51,3 @@ class AAAA(dns.rdata.Rdata): return cls(rdclass, rdtype, address) from_wire = classmethod(from_wire) - - def _cmp(self, other): - sa = dns.inet.inet_pton(dns.inet.AF_INET6, self.address) - oa = dns.inet.inet_pton(dns.inet.AF_INET6, other.address) - return cmp(sa, oa) diff --git a/dns/rdtypes/IN/APL.py b/dns/rdtypes/IN/APL.py index 59da75b9..6239f078 100644 --- a/dns/rdtypes/IN/APL.py +++ b/dns/rdtypes/IN/APL.py @@ -156,15 +156,3 @@ class APL(dns.rdata.Rdata): return cls(rdclass, rdtype, items) from_wire = classmethod(from_wire) - - def _cmp(self, other): - f = cStringIO.StringIO() - self.to_wire(f) - wire1 = f.getvalue() - f.seek(0) - f.truncate() - other.to_wire(f) - wire2 = f.getvalue() - f.close() - - return cmp(wire1, wire2) diff --git a/dns/rdtypes/IN/DHCID.py b/dns/rdtypes/IN/DHCID.py index 5524bead..705e4a4e 100644 --- a/dns/rdtypes/IN/DHCID.py +++ b/dns/rdtypes/IN/DHCID.py @@ -55,6 +55,3 @@ class DHCID(dns.rdata.Rdata): return cls(rdclass, rdtype, data) from_wire = classmethod(from_wire) - - def _cmp(self, other): - return cmp(self.data, other.data) diff --git a/dns/rdtypes/IN/IPSECKEY.py b/dns/rdtypes/IN/IPSECKEY.py index d85b6fe9..d5d16bd8 100644 --- a/dns/rdtypes/IN/IPSECKEY.py +++ b/dns/rdtypes/IN/IPSECKEY.py @@ -145,15 +145,3 @@ class IPSECKEY(dns.rdata.Rdata): gateway, key) from_wire = classmethod(from_wire) - - def _cmp(self, other): - f = cStringIO.StringIO() - self.to_wire(f) - wire1 = f.getvalue() - f.seek(0) - f.truncate() - other.to_wire(f) - wire2 = f.getvalue() - f.close() - - return cmp(wire1, wire2) diff --git a/dns/rdtypes/IN/NAPTR.py b/dns/rdtypes/IN/NAPTR.py index 7fe04308..1357c669 100644 --- a/dns/rdtypes/IN/NAPTR.py +++ b/dns/rdtypes/IN/NAPTR.py @@ -116,17 +116,3 @@ class NAPTR(dns.rdata.Rdata): def choose_relativity(self, origin = None, relativize = True): self.replacement = self.replacement.choose_relativity(origin, relativize) - - def _cmp(self, other): - sp = struct.pack("!HH", self.order, self.preference) - op = struct.pack("!HH", other.order, other.preference) - v = cmp(sp, op) - if v == 0: - v = cmp(self.flags, other.flags) - if v == 0: - v = cmp(self.service, other.service) - if v == 0: - v = cmp(self.regexp, other.regexp) - if v == 0: - v = cmp(self.replacement, other.replacement) - return v diff --git a/dns/rdtypes/IN/NSAP.py b/dns/rdtypes/IN/NSAP.py index 216cb0a8..c2040639 100644 --- a/dns/rdtypes/IN/NSAP.py +++ b/dns/rdtypes/IN/NSAP.py @@ -54,6 +54,3 @@ class NSAP(dns.rdata.Rdata): return cls(rdclass, rdtype, address) from_wire = classmethod(from_wire) - - def _cmp(self, other): - return cmp(self.address, other.address) diff --git a/dns/rdtypes/IN/PX.py b/dns/rdtypes/IN/PX.py index 1422b834..1b86789e 100644 --- a/dns/rdtypes/IN/PX.py +++ b/dns/rdtypes/IN/PX.py @@ -85,13 +85,3 @@ class PX(dns.rdata.Rdata): def choose_relativity(self, origin = None, relativize = True): self.map822 = self.map822.choose_relativity(origin, relativize) self.mapx400 = self.mapx400.choose_relativity(origin, relativize) - - def _cmp(self, other): - sp = struct.pack("!H", self.preference) - op = struct.pack("!H", other.preference) - v = cmp(sp, op) - if v == 0: - v = cmp(self.map822, other.map822) - if v == 0: - v = cmp(self.mapx400, other.mapx400) - return v diff --git a/dns/rdtypes/IN/SRV.py b/dns/rdtypes/IN/SRV.py index e101b26b..5da202b8 100644 --- a/dns/rdtypes/IN/SRV.py +++ b/dns/rdtypes/IN/SRV.py @@ -79,11 +79,3 @@ class SRV(dns.rdata.Rdata): def choose_relativity(self, origin = None, relativize = True): self.target = self.target.choose_relativity(origin, relativize) - - def _cmp(self, other): - sp = struct.pack("!HHH", self.priority, self.weight, self.port) - op = struct.pack("!HHH", other.priority, other.weight, other.port) - v = cmp(sp, op) - if v == 0: - v = cmp(self.target, other.target) - return v diff --git a/dns/rdtypes/IN/WKS.py b/dns/rdtypes/IN/WKS.py index 04c3054e..9d015044 100644 --- a/dns/rdtypes/IN/WKS.py +++ b/dns/rdtypes/IN/WKS.py @@ -99,15 +99,3 @@ class WKS(dns.rdata.Rdata): return cls(rdclass, rdtype, address, protocol, bitmap) from_wire = classmethod(from_wire) - - def _cmp(self, other): - sa = dns.ipv4.inet_aton(self.address) - oa = dns.ipv4.inet_aton(other.address) - v = cmp(sa, oa) - if v == 0: - sp = struct.pack('!B', self.protocol) - op = struct.pack('!B', other.protocol) - v = cmp(sp, op) - if v == 0: - v = cmp(self.bitmap, other.bitmap) - return v diff --git a/dns/rdtypes/dsbase.py b/dns/rdtypes/dsbase.py index 6f5559a7..abcc57a7 100644 --- a/dns/rdtypes/dsbase.py +++ b/dns/rdtypes/dsbase.py @@ -80,13 +80,3 @@ class DSBase(dns.rdata.Rdata): return cls(rdclass, rdtype, header[0], header[1], header[2], digest) from_wire = classmethod(from_wire) - - def _cmp(self, other): - hs = struct.pack("!HBB", self.key_tag, self.algorithm, - self.digest_type) - ho = struct.pack("!HBB", other.key_tag, other.algorithm, - other.digest_type) - v = cmp(hs, ho) - if v == 0: - v = cmp(self.digest, other.digest) - return v diff --git a/dns/rdtypes/mxbase.py b/dns/rdtypes/mxbase.py index abc6a9ed..754aff59 100644 --- a/dns/rdtypes/mxbase.py +++ b/dns/rdtypes/mxbase.py @@ -76,14 +76,6 @@ class MXBase(dns.rdata.Rdata): def choose_relativity(self, origin = None, relativize = True): self.exchange = self.exchange.choose_relativity(origin, relativize) - def _cmp(self, other): - sp = struct.pack("!H", self.preference) - op = struct.pack("!H", other.preference) - v = cmp(sp, op) - if v == 0: - v = cmp(self.exchange, other.exchange) - return v - class UncompressedMX(MXBase): """Base class for rdata that is like an MX record, but whose name is not compressed when converted to DNS wire format, and whose diff --git a/dns/rdtypes/nsbase.py b/dns/rdtypes/nsbase.py index fbd5ef1e..84f088a1 100644 --- a/dns/rdtypes/nsbase.py +++ b/dns/rdtypes/nsbase.py @@ -65,9 +65,6 @@ class NSBase(dns.rdata.Rdata): def choose_relativity(self, origin = None, relativize = True): self.target = self.target.choose_relativity(origin, relativize) - def _cmp(self, other): - return cmp(self.target, other.target) - class UncompressedNS(NSBase): """Base class for rdata that is like an NS record, but whose name is not compressed when convert to DNS wire format, and whose diff --git a/dns/rdtypes/txtbase.py b/dns/rdtypes/txtbase.py index 580f056e..cf4b4cef 100644 --- a/dns/rdtypes/txtbase.py +++ b/dns/rdtypes/txtbase.py @@ -82,6 +82,3 @@ class TXTBase(dns.rdata.Rdata): return cls(rdclass, rdtype, strings) from_wire = classmethod(from_wire) - - def _cmp(self, other): - return cmp(self.strings, other.strings)