2014-09-04 Bob Halley <halley@dnspython.org>
+ * 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.
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):
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.
from_wire = classmethod(from_wire)
- def _cmp(self, other):
- return cmp(self.data, other.data)
-
_rdata_modules = {}
_module_prefix = 'dns.rdtypes'
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
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)
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])"""
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)
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
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
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
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)
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)
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())
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())
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
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)
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
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
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
return cls(rdclass, rdtype, address)
from_wire = classmethod(from_wire)
-
- def _cmp(self, other):
- return cmp(self.address, other.address)
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)
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)
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)
return cls(rdclass, rdtype, data)
from_wire = classmethod(from_wire)
-
- def _cmp(self, other):
- return cmp(self.data, other.data)
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)
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
return cls(rdclass, rdtype, address)
from_wire = classmethod(from_wire)
-
- def _cmp(self, other):
- return cmp(self.address, other.address)
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
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
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
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
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
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
return cls(rdclass, rdtype, strings)
from_wire = classmethod(from_wire)
-
- def _cmp(self, other):
- return cmp(self.strings, other.strings)