From 8bd71350abe48fdcfc0125e48fa97abdf31e1270 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 27 Aug 2011 16:07:52 +0200 Subject: dnspython: Update to latest upstream snapshot. Autobuild-User: Jelmer Vernooij Autobuild-Date: Sat Aug 27 17:40:39 CEST 2011 on sn-devel-104 --- lib/dnspython/dns/rdtypes/ANY/AFSDB.py | 2 +- lib/dnspython/dns/rdtypes/ANY/CERT.py | 6 +- lib/dnspython/dns/rdtypes/ANY/CNAME.py | 2 +- lib/dnspython/dns/rdtypes/ANY/DLV.py | 2 +- lib/dnspython/dns/rdtypes/ANY/DNAME.py | 2 +- lib/dnspython/dns/rdtypes/ANY/DNSKEY.py | 79 ++++++++++++- lib/dnspython/dns/rdtypes/ANY/DS.py | 2 +- lib/dnspython/dns/rdtypes/ANY/GPOS.py | 18 +-- lib/dnspython/dns/rdtypes/ANY/HINFO.py | 14 +-- lib/dnspython/dns/rdtypes/ANY/HIP.py | 6 +- lib/dnspython/dns/rdtypes/ANY/ISDN.py | 6 +- lib/dnspython/dns/rdtypes/ANY/KEY.py | 20 ---- lib/dnspython/dns/rdtypes/ANY/LOC.py | 2 +- lib/dnspython/dns/rdtypes/ANY/MX.py | 2 +- lib/dnspython/dns/rdtypes/ANY/NS.py | 2 +- lib/dnspython/dns/rdtypes/ANY/NSEC.py | 21 +--- lib/dnspython/dns/rdtypes/ANY/NSEC3.py | 10 +- lib/dnspython/dns/rdtypes/ANY/NSEC3PARAM.py | 4 +- lib/dnspython/dns/rdtypes/ANY/NXT.py | 99 ---------------- lib/dnspython/dns/rdtypes/ANY/PTR.py | 2 +- lib/dnspython/dns/rdtypes/ANY/RP.py | 2 +- lib/dnspython/dns/rdtypes/ANY/RRSIG.py | 143 ++++++++++++++++++++++- lib/dnspython/dns/rdtypes/ANY/RT.py | 2 +- lib/dnspython/dns/rdtypes/ANY/SIG.py | 26 ----- lib/dnspython/dns/rdtypes/ANY/SOA.py | 8 +- lib/dnspython/dns/rdtypes/ANY/SPF.py | 2 +- lib/dnspython/dns/rdtypes/ANY/SSHFP.py | 12 +- lib/dnspython/dns/rdtypes/ANY/TXT.py | 2 +- lib/dnspython/dns/rdtypes/ANY/X25.py | 12 +- lib/dnspython/dns/rdtypes/ANY/__init__.py | 5 +- lib/dnspython/dns/rdtypes/IN/A.py | 2 +- lib/dnspython/dns/rdtypes/IN/AAAA.py | 2 +- lib/dnspython/dns/rdtypes/IN/APL.py | 4 +- lib/dnspython/dns/rdtypes/IN/DHCID.py | 4 +- lib/dnspython/dns/rdtypes/IN/IPSECKEY.py | 4 +- lib/dnspython/dns/rdtypes/IN/KX.py | 2 +- lib/dnspython/dns/rdtypes/IN/NAPTR.py | 12 +- lib/dnspython/dns/rdtypes/IN/NSAP.py | 4 +- lib/dnspython/dns/rdtypes/IN/NSAP_PTR.py | 2 +- lib/dnspython/dns/rdtypes/IN/PX.py | 10 +- lib/dnspython/dns/rdtypes/IN/SRV.py | 2 +- lib/dnspython/dns/rdtypes/IN/WKS.py | 4 +- lib/dnspython/dns/rdtypes/IN/__init__.py | 2 +- lib/dnspython/dns/rdtypes/__init__.py | 4 +- lib/dnspython/dns/rdtypes/dsbase.py | 4 +- lib/dnspython/dns/rdtypes/keybase.py | 149 ------------------------ lib/dnspython/dns/rdtypes/mxbase.py | 2 +- lib/dnspython/dns/rdtypes/nsbase.py | 2 +- lib/dnspython/dns/rdtypes/sigbase.py | 168 ---------------------------- lib/dnspython/dns/rdtypes/txtbase.py | 4 +- 50 files changed, 313 insertions(+), 589 deletions(-) delete mode 100644 lib/dnspython/dns/rdtypes/ANY/KEY.py delete mode 100644 lib/dnspython/dns/rdtypes/ANY/NXT.py delete mode 100644 lib/dnspython/dns/rdtypes/ANY/SIG.py delete mode 100644 lib/dnspython/dns/rdtypes/keybase.py delete mode 100644 lib/dnspython/dns/rdtypes/sigbase.py (limited to 'lib/dnspython/dns/rdtypes') diff --git a/lib/dnspython/dns/rdtypes/ANY/AFSDB.py b/lib/dnspython/dns/rdtypes/ANY/AFSDB.py index e8ca6f5cbb..c729789afa 100644 --- a/lib/dnspython/dns/rdtypes/ANY/AFSDB.py +++ b/lib/dnspython/dns/rdtypes/ANY/AFSDB.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/CERT.py b/lib/dnspython/dns/rdtypes/ANY/CERT.py index d2703519d5..c102521a14 100644 --- a/lib/dnspython/dns/rdtypes/ANY/CERT.py +++ b/lib/dnspython/dns/rdtypes/ANY/CERT.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -106,13 +106,13 @@ class CERT(dns.rdata.Rdata): file.write(self.certificate) def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): - prefix = wire[current : current + 5] + prefix = wire[current : current + 5].unwrap() current += 5 rdlen -= 5 if rdlen < 0: raise dns.exception.FormError (certificate_type, key_tag, algorithm) = struct.unpack("!HHB", prefix) - certificate = wire[current : current + rdlen] + certificate = wire[current : current + rdlen].unwrap() return cls(rdclass, rdtype, certificate_type, key_tag, algorithm, certificate) diff --git a/lib/dnspython/dns/rdtypes/ANY/CNAME.py b/lib/dnspython/dns/rdtypes/ANY/CNAME.py index 7f5c4b3bd7..fb8e9be49e 100644 --- a/lib/dnspython/dns/rdtypes/ANY/CNAME.py +++ b/lib/dnspython/dns/rdtypes/ANY/CNAME.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/DLV.py b/lib/dnspython/dns/rdtypes/ANY/DLV.py index 07b9548342..8bd79793d1 100644 --- a/lib/dnspython/dns/rdtypes/ANY/DLV.py +++ b/lib/dnspython/dns/rdtypes/ANY/DLV.py @@ -1,4 +1,4 @@ -# Copyright (C) 2009, 2010 Nominum, Inc. +# Copyright (C) 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/DNAME.py b/lib/dnspython/dns/rdtypes/ANY/DNAME.py index 99b5013f33..d864001190 100644 --- a/lib/dnspython/dns/rdtypes/ANY/DNAME.py +++ b/lib/dnspython/dns/rdtypes/ANY/DNAME.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/DNSKEY.py b/lib/dnspython/dns/rdtypes/ANY/DNSKEY.py index ad66ef0c69..1d678d2f2a 100644 --- a/lib/dnspython/dns/rdtypes/ANY/DNSKEY.py +++ b/lib/dnspython/dns/rdtypes/ANY/DNSKEY.py @@ -1,4 +1,4 @@ -# Copyright (C) 2004-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -13,13 +13,82 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -import dns.rdtypes.keybase + +import struct + +import dns.exception +import dns.dnssec +import dns.rdata # flag constants SEP = 0x0001 REVOKE = 0x0080 ZONE = 0x0100 -class DNSKEY(dns.rdtypes.keybase.KEYBase): - """DNSKEY record""" - pass +class DNSKEY(dns.rdata.Rdata): + """DNSKEY record + + @ivar flags: the key flags + @type flags: int + @ivar protocol: the protocol for which this key may be used + @type protocol: int + @ivar algorithm: the algorithm used for the key + @type algorithm: int + @ivar key: the public key + @type key: string""" + + __slots__ = ['flags', 'protocol', 'algorithm', 'key'] + + def __init__(self, rdclass, rdtype, flags, protocol, algorithm, key): + super(DNSKEY, self).__init__(rdclass, rdtype) + self.flags = flags + self.protocol = protocol + self.algorithm = algorithm + self.key = key + + def to_text(self, origin=None, relativize=True, **kw): + return '%d %d %d %s' % (self.flags, self.protocol, self.algorithm, + dns.rdata._base64ify(self.key)) + + def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): + flags = tok.get_uint16() + protocol = tok.get_uint8() + algorithm = dns.dnssec.algorithm_from_text(tok.get_string()) + chunks = [] + while 1: + t = tok.get().unescape() + if t.is_eol_or_eof(): + break + if not t.is_identifier(): + raise dns.exception.SyntaxError + chunks.append(t.value) + b64 = ''.join(chunks) + key = b64.decode('base64_codec') + return cls(rdclass, rdtype, flags, protocol, algorithm, key) + + from_text = classmethod(from_text) + + def to_wire(self, file, compress = None, origin = None): + header = struct.pack("!HBB", self.flags, self.protocol, self.algorithm) + file.write(header) + file.write(self.key) + + def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): + if rdlen < 4: + raise dns.exception.FormError + header = struct.unpack('!HBB', wire[current : current + 4]) + current += 4 + rdlen -= 4 + key = wire[current : current + rdlen].unwrap() + return cls(rdclass, rdtype, header[0], header[1], header[2], + key) + + 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 diff --git a/lib/dnspython/dns/rdtypes/ANY/DS.py b/lib/dnspython/dns/rdtypes/ANY/DS.py index 3a06f448f7..56b6332de2 100644 --- a/lib/dnspython/dns/rdtypes/ANY/DS.py +++ b/lib/dnspython/dns/rdtypes/ANY/DS.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/GPOS.py b/lib/dnspython/dns/rdtypes/ANY/GPOS.py index 6f63cc05f6..38d1d88b28 100644 --- a/lib/dnspython/dns/rdtypes/ANY/GPOS.py +++ b/lib/dnspython/dns/rdtypes/ANY/GPOS.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -29,7 +29,7 @@ def _validate_float_string(what): raise dns.exception.FormError if not right == '' and not right.isdigit(): raise dns.exception.FormError - + class GPOS(dns.rdata.Rdata): """GPOS record @@ -42,7 +42,7 @@ class GPOS(dns.rdata.Rdata): @see: RFC 1712""" __slots__ = ['latitude', 'longitude', 'altitude'] - + def __init__(self, rdclass, rdtype, latitude, longitude, altitude): super(GPOS, self).__init__(rdclass, rdtype) if isinstance(latitude, float) or \ @@ -66,14 +66,14 @@ class GPOS(dns.rdata.Rdata): def to_text(self, origin=None, relativize=True, **kw): return '%s %s %s' % (self.latitude, self.longitude, self.altitude) - + def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): latitude = tok.get_string() longitude = tok.get_string() altitude = tok.get_string() tok.get_eol() return cls(rdclass, rdtype, latitude, longitude, altitude) - + from_text = classmethod(from_text) def to_wire(self, file, compress = None, origin = None): @@ -92,14 +92,14 @@ class GPOS(dns.rdata.Rdata): byte = chr(l) file.write(byte) file.write(self.altitude) - + def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): l = ord(wire[current]) current += 1 rdlen -= 1 if l > rdlen: raise dns.exception.FormError - latitude = wire[current : current + l] + latitude = wire[current : current + l].unwrap() current += l rdlen -= l l = ord(wire[current]) @@ -107,7 +107,7 @@ class GPOS(dns.rdata.Rdata): rdlen -= 1 if l > rdlen: raise dns.exception.FormError - longitude = wire[current : current + l] + longitude = wire[current : current + l].unwrap() current += l rdlen -= l l = ord(wire[current]) @@ -115,7 +115,7 @@ class GPOS(dns.rdata.Rdata): rdlen -= 1 if l != rdlen: raise dns.exception.FormError - altitude = wire[current : current + l] + altitude = wire[current : current + l].unwrap() return cls(rdclass, rdtype, latitude, longitude, altitude) from_wire = classmethod(from_wire) diff --git a/lib/dnspython/dns/rdtypes/ANY/HINFO.py b/lib/dnspython/dns/rdtypes/ANY/HINFO.py index e592ad39a7..15fd54e69e 100644 --- a/lib/dnspython/dns/rdtypes/ANY/HINFO.py +++ b/lib/dnspython/dns/rdtypes/ANY/HINFO.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -27,7 +27,7 @@ class HINFO(dns.rdata.Rdata): @see: RFC 1035""" __slots__ = ['cpu', 'os'] - + def __init__(self, rdclass, rdtype, cpu, os): super(HINFO, self).__init__(rdclass, rdtype) self.cpu = cpu @@ -36,13 +36,13 @@ class HINFO(dns.rdata.Rdata): def to_text(self, origin=None, relativize=True, **kw): return '"%s" "%s"' % (dns.rdata._escapify(self.cpu), dns.rdata._escapify(self.os)) - + def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): cpu = tok.get_string() os = tok.get_string() tok.get_eol() return cls(rdclass, rdtype, cpu, os) - + from_text = classmethod(from_text) def to_wire(self, file, compress = None, origin = None): @@ -56,14 +56,14 @@ class HINFO(dns.rdata.Rdata): byte = chr(l) file.write(byte) file.write(self.os) - + def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): l = ord(wire[current]) current += 1 rdlen -= 1 if l > rdlen: raise dns.exception.FormError - cpu = wire[current : current + l] + cpu = wire[current : current + l].unwrap() current += l rdlen -= l l = ord(wire[current]) @@ -71,7 +71,7 @@ class HINFO(dns.rdata.Rdata): rdlen -= 1 if l != rdlen: raise dns.exception.FormError - os = wire[current : current + l] + os = wire[current : current + l].unwrap() return cls(rdclass, rdtype, cpu, os) from_wire = classmethod(from_wire) diff --git a/lib/dnspython/dns/rdtypes/ANY/HIP.py b/lib/dnspython/dns/rdtypes/ANY/HIP.py index 8f96ae93d6..968b36f5e2 100644 --- a/lib/dnspython/dns/rdtypes/ANY/HIP.py +++ b/lib/dnspython/dns/rdtypes/ANY/HIP.py @@ -1,4 +1,4 @@ -# Copyright (C) 2010 Nominum, Inc. +# Copyright (C) 2010, 2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -86,10 +86,10 @@ class HIP(dns.rdata.Rdata): wire[current : current + 4]) current += 4 rdlen -= 4 - hit = wire[current : current + lh] + hit = wire[current : current + lh].unwrap() current += lh rdlen -= lh - key = wire[current : current + lk] + key = wire[current : current + lk].unwrap() current += lk rdlen -= lk servers = [] diff --git a/lib/dnspython/dns/rdtypes/ANY/ISDN.py b/lib/dnspython/dns/rdtypes/ANY/ISDN.py index 424d3a9a3c..0c2d3cd035 100644 --- a/lib/dnspython/dns/rdtypes/ANY/ISDN.py +++ b/lib/dnspython/dns/rdtypes/ANY/ISDN.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -73,7 +73,7 @@ class ISDN(dns.rdata.Rdata): rdlen -= 1 if l > rdlen: raise dns.exception.FormError - address = wire[current : current + l] + address = wire[current : current + l].unwrap() current += l rdlen -= l if rdlen > 0: @@ -82,7 +82,7 @@ class ISDN(dns.rdata.Rdata): rdlen -= 1 if l != rdlen: raise dns.exception.FormError - subaddress = wire[current : current + l] + subaddress = wire[current : current + l].unwrap() else: subaddress = '' return cls(rdclass, rdtype, address, subaddress) diff --git a/lib/dnspython/dns/rdtypes/ANY/KEY.py b/lib/dnspython/dns/rdtypes/ANY/KEY.py deleted file mode 100644 index c8581edbeb..0000000000 --- a/lib/dnspython/dns/rdtypes/ANY/KEY.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import dns.rdtypes.keybase - -class KEY(dns.rdtypes.keybase.KEYBase): - """KEY record""" - pass diff --git a/lib/dnspython/dns/rdtypes/ANY/LOC.py b/lib/dnspython/dns/rdtypes/ANY/LOC.py index 518dd6010f..154546d79d 100644 --- a/lib/dnspython/dns/rdtypes/ANY/LOC.py +++ b/lib/dnspython/dns/rdtypes/ANY/LOC.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/MX.py b/lib/dnspython/dns/rdtypes/ANY/MX.py index 9cad260672..92f41532a7 100644 --- a/lib/dnspython/dns/rdtypes/ANY/MX.py +++ b/lib/dnspython/dns/rdtypes/ANY/MX.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/NS.py b/lib/dnspython/dns/rdtypes/ANY/NS.py index 4b03a3ab47..6b45d4d4b6 100644 --- a/lib/dnspython/dns/rdtypes/ANY/NS.py +++ b/lib/dnspython/dns/rdtypes/ANY/NS.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/NSEC.py b/lib/dnspython/dns/rdtypes/ANY/NSEC.py index 72859ce108..ad113a4b59 100644 --- a/lib/dnspython/dns/rdtypes/ANY/NSEC.py +++ b/lib/dnspython/dns/rdtypes/ANY/NSEC.py @@ -1,4 +1,4 @@ -# Copyright (C) 2004-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -79,7 +79,7 @@ class NSEC(dns.rdata.Rdata): bitmap = ['\0'] * 32 window = new_window offset = nrdtype % 256 - byte = offset / 8 + byte = offset // 8 bit = offset % 8 octets = byte + 1 bitmap[byte] = chr(ord(bitmap[byte]) | (0x80 >> bit)) @@ -111,7 +111,7 @@ class NSEC(dns.rdata.Rdata): rdlen -= 2 if rdlen < octets: raise dns.exception.FormError("bad NSEC bitmap length") - bitmap = wire[current : current + octets] + bitmap = wire[current : current + octets].unwrap() current += octets rdlen -= octets windows.append((window, bitmap)) @@ -125,17 +125,4 @@ class NSEC(dns.rdata.Rdata): self.next = self.next.choose_relativity(origin, relativize) def _cmp(self, other): - v = cmp(self.next, other.next) - if v == 0: - b1 = cStringIO.StringIO() - for (window, bitmap) in self.windows: - b1.write(chr(window)) - b1.write(chr(len(bitmap))) - b1.write(bitmap) - b2 = cStringIO.StringIO() - for (window, bitmap) in other.windows: - b2.write(chr(window)) - b2.write(chr(len(bitmap))) - b2.write(bitmap) - v = cmp(b1.getvalue(), b2.getvalue()) - return v + return self._wire_cmp(other) diff --git a/lib/dnspython/dns/rdtypes/ANY/NSEC3.py b/lib/dnspython/dns/rdtypes/ANY/NSEC3.py index 932d7b4032..c7ac7375b4 100644 --- a/lib/dnspython/dns/rdtypes/ANY/NSEC3.py +++ b/lib/dnspython/dns/rdtypes/ANY/NSEC3.py @@ -1,4 +1,4 @@ -# Copyright (C) 2004-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -118,7 +118,7 @@ class NSEC3(dns.rdata.Rdata): bitmap = ['\0'] * 32 window = new_window offset = nrdtype % 256 - byte = offset / 8 + byte = offset // 8 bit = offset % 8 octets = byte + 1 bitmap[byte] = chr(ord(bitmap[byte]) | (0x80 >> bit)) @@ -145,13 +145,13 @@ class NSEC3(dns.rdata.Rdata): wire[current : current + 5]) current += 5 rdlen -= 5 - salt = wire[current : current + slen] + salt = wire[current : current + slen].unwrap() current += slen rdlen -= slen (nlen, ) = struct.unpack('!B', wire[current]) current += 1 rdlen -= 1 - next = wire[current : current + nlen] + next = wire[current : current + nlen].unwrap() current += nlen rdlen -= nlen windows = [] @@ -166,7 +166,7 @@ class NSEC3(dns.rdata.Rdata): rdlen -= 2 if rdlen < octets: raise dns.exception.FormError("bad NSEC3 bitmap length") - bitmap = wire[current : current + octets] + bitmap = wire[current : current + octets].unwrap() current += octets rdlen -= octets windows.append((window, bitmap)) diff --git a/lib/dnspython/dns/rdtypes/ANY/NSEC3PARAM.py b/lib/dnspython/dns/rdtypes/ANY/NSEC3PARAM.py index ec91e5e85c..4e687825ad 100644 --- a/lib/dnspython/dns/rdtypes/ANY/NSEC3PARAM.py +++ b/lib/dnspython/dns/rdtypes/ANY/NSEC3PARAM.py @@ -1,4 +1,4 @@ -# Copyright (C) 2004-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -71,7 +71,7 @@ class NSEC3PARAM(dns.rdata.Rdata): wire[current : current + 5]) current += 5 rdlen -= 5 - salt = wire[current : current + slen] + salt = wire[current : current + slen].unwrap() current += slen rdlen -= slen if rdlen != 0: diff --git a/lib/dnspython/dns/rdtypes/ANY/NXT.py b/lib/dnspython/dns/rdtypes/ANY/NXT.py deleted file mode 100644 index 99ae9b9dff..0000000000 --- a/lib/dnspython/dns/rdtypes/ANY/NXT.py +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import dns.exception -import dns.rdata -import dns.rdatatype -import dns.name - -class NXT(dns.rdata.Rdata): - """NXT record - - @ivar next: the next name - @type next: dns.name.Name object - @ivar bitmap: the type bitmap - @type bitmap: string - @see: RFC 2535""" - - __slots__ = ['next', 'bitmap'] - - def __init__(self, rdclass, rdtype, next, bitmap): - super(NXT, self).__init__(rdclass, rdtype) - self.next = next - self.bitmap = bitmap - - def to_text(self, origin=None, relativize=True, **kw): - next = self.next.choose_relativity(origin, relativize) - bits = [] - for i in xrange(0, len(self.bitmap)): - byte = ord(self.bitmap[i]) - for j in xrange(0, 8): - if byte & (0x80 >> j): - bits.append(dns.rdatatype.to_text(i * 8 + j)) - text = ' '.join(bits) - return '%s %s' % (next, text) - - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): - next = tok.get_name() - next = next.choose_relativity(origin, relativize) - bitmap = ['\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00', - '\x00', '\x00', '\x00', '\x00' ] - while 1: - token = tok.get().unescape() - if token.is_eol_or_eof(): - break - if token.value.isdigit(): - nrdtype = int(token.value) - else: - nrdtype = dns.rdatatype.from_text(token.value) - if nrdtype == 0: - raise dns.exception.SyntaxError("NXT with bit 0") - if nrdtype > 127: - raise dns.exception.SyntaxError("NXT with bit > 127") - i = nrdtype // 8 - bitmap[i] = chr(ord(bitmap[i]) | (0x80 >> (nrdtype % 8))) - bitmap = dns.rdata._truncate_bitmap(bitmap) - return cls(rdclass, rdtype, next, bitmap) - - from_text = classmethod(from_text) - - def to_wire(self, file, compress = None, origin = None): - self.next.to_wire(file, None, origin) - file.write(self.bitmap) - - def to_digestable(self, origin = None): - return self.next.to_digestable(origin) + self.bitmap - - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): - (next, cused) = dns.name.from_wire(wire[: current + rdlen], current) - current += cused - rdlen -= cused - bitmap = wire[current : current + rdlen] - if not origin is None: - next = next.relativize(origin) - return cls(rdclass, rdtype, next, bitmap) - - from_wire = classmethod(from_wire) - - def choose_relativity(self, origin = None, relativize = True): - self.next = self.next.choose_relativity(origin, relativize) - - def _cmp(self, other): - v = cmp(self.next, other.next) - if v == 0: - v = cmp(self.bitmap, other.bitmap) - return v diff --git a/lib/dnspython/dns/rdtypes/ANY/PTR.py b/lib/dnspython/dns/rdtypes/ANY/PTR.py index 6c4b79eaac..4a037537b6 100644 --- a/lib/dnspython/dns/rdtypes/ANY/PTR.py +++ b/lib/dnspython/dns/rdtypes/ANY/PTR.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/RP.py b/lib/dnspython/dns/rdtypes/ANY/RP.py index 421ce8e207..26c55314e1 100644 --- a/lib/dnspython/dns/rdtypes/ANY/RP.py +++ b/lib/dnspython/dns/rdtypes/ANY/RP.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/RRSIG.py b/lib/dnspython/dns/rdtypes/ANY/RRSIG.py index 0e4816f648..63d389cd7a 100644 --- a/lib/dnspython/dns/rdtypes/ANY/RRSIG.py +++ b/lib/dnspython/dns/rdtypes/ANY/RRSIG.py @@ -1,4 +1,4 @@ -# Copyright (C) 2004-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -13,8 +13,143 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -import dns.rdtypes.sigbase +import calendar +import struct +import time -class RRSIG(dns.rdtypes.sigbase.SIGBase): - """RRSIG record""" +import dns.dnssec +import dns.exception +import dns.rdata +import dns.rdatatype + +class BadSigTime(dns.exception.DNSException): + """Raised when a SIG or RRSIG RR's time cannot be parsed.""" pass + +def sigtime_to_posixtime(what): + if len(what) != 14: + raise BadSigTime + year = int(what[0:4]) + month = int(what[4:6]) + day = int(what[6:8]) + hour = int(what[8:10]) + minute = int(what[10:12]) + second = int(what[12:14]) + return calendar.timegm((year, month, day, hour, minute, second, + 0, 0, 0)) + +def posixtime_to_sigtime(what): + return time.strftime('%Y%m%d%H%M%S', time.gmtime(what)) + +class RRSIG(dns.rdata.Rdata): + """RRSIG record + + @ivar type_covered: the rdata type this signature covers + @type type_covered: int + @ivar algorithm: the algorithm used for the sig + @type algorithm: int + @ivar labels: number of labels + @type labels: int + @ivar original_ttl: the original TTL + @type original_ttl: long + @ivar expiration: signature expiration time + @type expiration: long + @ivar inception: signature inception time + @type inception: long + @ivar key_tag: the key tag + @type key_tag: int + @ivar signer: the signer + @type signer: dns.name.Name object + @ivar signature: the signature + @type signature: string""" + + __slots__ = ['type_covered', 'algorithm', 'labels', 'original_ttl', + 'expiration', 'inception', 'key_tag', 'signer', + 'signature'] + + def __init__(self, rdclass, rdtype, type_covered, algorithm, labels, + original_ttl, expiration, inception, key_tag, signer, + signature): + super(RRSIG, self).__init__(rdclass, rdtype) + self.type_covered = type_covered + self.algorithm = algorithm + self.labels = labels + self.original_ttl = original_ttl + self.expiration = expiration + self.inception = inception + self.key_tag = key_tag + self.signer = signer + self.signature = signature + + def covers(self): + return self.type_covered + + def to_text(self, origin=None, relativize=True, **kw): + return '%s %d %d %d %s %s %d %s %s' % ( + dns.rdatatype.to_text(self.type_covered), + self.algorithm, + self.labels, + self.original_ttl, + posixtime_to_sigtime(self.expiration), + posixtime_to_sigtime(self.inception), + self.key_tag, + self.signer, + dns.rdata._base64ify(self.signature) + ) + + def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): + type_covered = dns.rdatatype.from_text(tok.get_string()) + algorithm = dns.dnssec.algorithm_from_text(tok.get_string()) + labels = tok.get_int() + original_ttl = tok.get_ttl() + expiration = sigtime_to_posixtime(tok.get_string()) + inception = sigtime_to_posixtime(tok.get_string()) + key_tag = tok.get_int() + signer = tok.get_name() + signer = signer.choose_relativity(origin, relativize) + chunks = [] + while 1: + t = tok.get().unescape() + if t.is_eol_or_eof(): + break + if not t.is_identifier(): + raise dns.exception.SyntaxError + chunks.append(t.value) + b64 = ''.join(chunks) + signature = b64.decode('base64_codec') + return cls(rdclass, rdtype, type_covered, algorithm, labels, + original_ttl, expiration, inception, key_tag, signer, + signature) + + from_text = classmethod(from_text) + + def to_wire(self, file, compress = None, origin = None): + header = struct.pack('!HBBIIIH', self.type_covered, + self.algorithm, self.labels, + self.original_ttl, self.expiration, + self.inception, self.key_tag) + file.write(header) + self.signer.to_wire(file, None, origin) + file.write(self.signature) + + def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): + header = struct.unpack('!HBBIIIH', wire[current : current + 18]) + current += 18 + rdlen -= 18 + (signer, cused) = dns.name.from_wire(wire[: current + rdlen], current) + current += cused + rdlen -= cused + if not origin is None: + signer = signer.relativize(origin) + signature = wire[current : current + rdlen].unwrap() + return cls(rdclass, rdtype, header[0], header[1], header[2], + header[3], header[4], header[5], header[6], signer, + signature) + + from_wire = classmethod(from_wire) + + 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/lib/dnspython/dns/rdtypes/ANY/RT.py b/lib/dnspython/dns/rdtypes/ANY/RT.py index 1efd3724d9..f9653fdb34 100644 --- a/lib/dnspython/dns/rdtypes/ANY/RT.py +++ b/lib/dnspython/dns/rdtypes/ANY/RT.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/SIG.py b/lib/dnspython/dns/rdtypes/ANY/SIG.py deleted file mode 100644 index 501e29cc8c..0000000000 --- a/lib/dnspython/dns/rdtypes/ANY/SIG.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import dns.rdtypes.sigbase - -class SIG(dns.rdtypes.sigbase.SIGBase): - """SIG record""" - def to_digestable(self, origin = None): - return struct.pack('!HBBIIIH', self.type_covered, - self.algorithm, self.labels, - self.original_ttl, self.expiration, - self.inception, self.key_tag) + \ - self.signer.to_digestable(origin) + \ - self.signature diff --git a/lib/dnspython/dns/rdtypes/ANY/SOA.py b/lib/dnspython/dns/rdtypes/ANY/SOA.py index a25a35e29b..2d6f21b56b 100644 --- a/lib/dnspython/dns/rdtypes/ANY/SOA.py +++ b/lib/dnspython/dns/rdtypes/ANY/SOA.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -41,7 +41,7 @@ class SOA(dns.rdata.Rdata): __slots__ = ['mname', 'rname', 'serial', 'refresh', 'retry', 'expire', 'minimum'] - + def __init__(self, rdclass, rdtype, mname, rname, serial, refresh, retry, expire, minimum): super(SOA, self).__init__(rdclass, rdtype) @@ -59,7 +59,7 @@ class SOA(dns.rdata.Rdata): return '%s %s %d %d %d %d %d' % ( mname, rname, self.serial, self.refresh, self.retry, self.expire, self.minimum ) - + def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): mname = tok.get_name() rname = tok.get_name() @@ -73,7 +73,7 @@ class SOA(dns.rdata.Rdata): tok.get_eol() return cls(rdclass, rdtype, mname, rname, serial, refresh, retry, expire, minimum ) - + from_text = classmethod(from_text) def to_wire(self, file, compress = None, origin = None): diff --git a/lib/dnspython/dns/rdtypes/ANY/SPF.py b/lib/dnspython/dns/rdtypes/ANY/SPF.py index 9b5a9a9fed..8860dd72bb 100644 --- a/lib/dnspython/dns/rdtypes/ANY/SPF.py +++ b/lib/dnspython/dns/rdtypes/ANY/SPF.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, 2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/SSHFP.py b/lib/dnspython/dns/rdtypes/ANY/SSHFP.py index 162dda5c48..cec650a570 100644 --- a/lib/dnspython/dns/rdtypes/ANY/SSHFP.py +++ b/lib/dnspython/dns/rdtypes/ANY/SSHFP.py @@ -1,4 +1,4 @@ -# Copyright (C) 2005-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2005-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -30,7 +30,7 @@ class SSHFP(dns.rdata.Rdata): @see: draft-ietf-secsh-dns-05.txt""" __slots__ = ['algorithm', 'fp_type', 'fingerprint'] - + def __init__(self, rdclass, rdtype, algorithm, fp_type, fingerprint): super(SSHFP, self).__init__(rdclass, rdtype) @@ -43,7 +43,7 @@ class SSHFP(dns.rdata.Rdata): self.fp_type, dns.rdata._hexify(self.fingerprint, chunksize=128)) - + def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): algorithm = tok.get_uint8() fp_type = tok.get_uint8() @@ -51,19 +51,19 @@ class SSHFP(dns.rdata.Rdata): fingerprint = fingerprint.decode('hex_codec') tok.get_eol() return cls(rdclass, rdtype, algorithm, fp_type, fingerprint) - + from_text = classmethod(from_text) def to_wire(self, file, compress = None, origin = None): header = struct.pack("!BB", self.algorithm, self.fp_type) file.write(header) file.write(self.fingerprint) - + def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): header = struct.unpack("!BB", wire[current : current + 2]) current += 2 rdlen -= 2 - fingerprint = wire[current : current + rdlen] + fingerprint = wire[current : current + rdlen].unwrap() return cls(rdclass, rdtype, header[0], header[1], fingerprint) from_wire = classmethod(from_wire) diff --git a/lib/dnspython/dns/rdtypes/ANY/TXT.py b/lib/dnspython/dns/rdtypes/ANY/TXT.py index 23f4f3b7c6..604fd0f4de 100644 --- a/lib/dnspython/dns/rdtypes/ANY/TXT.py +++ b/lib/dnspython/dns/rdtypes/ANY/TXT.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/ANY/X25.py b/lib/dnspython/dns/rdtypes/ANY/X25.py index c3632f7fc4..ae91295f8c 100644 --- a/lib/dnspython/dns/rdtypes/ANY/X25.py +++ b/lib/dnspython/dns/rdtypes/ANY/X25.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -25,19 +25,19 @@ class X25(dns.rdata.Rdata): @see: RFC 1183""" __slots__ = ['address'] - + def __init__(self, rdclass, rdtype, address): super(X25, self).__init__(rdclass, rdtype) self.address = address def to_text(self, origin=None, relativize=True, **kw): return '"%s"' % dns.rdata._escapify(self.address) - + def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): address = tok.get_string() tok.get_eol() return cls(rdclass, rdtype, address) - + from_text = classmethod(from_text) def to_wire(self, file, compress = None, origin = None): @@ -46,14 +46,14 @@ class X25(dns.rdata.Rdata): byte = chr(l) file.write(byte) file.write(self.address) - + def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): l = ord(wire[current]) current += 1 rdlen -= 1 if l != rdlen: raise dns.exception.FormError - address = wire[current : current + l] + address = wire[current : current + l].unwrap() return cls(rdclass, rdtype, address) from_wire = classmethod(from_wire) diff --git a/lib/dnspython/dns/rdtypes/ANY/__init__.py b/lib/dnspython/dns/rdtypes/ANY/__init__.py index 0815dd5450..721e9dd60b 100644 --- a/lib/dnspython/dns/rdtypes/ANY/__init__.py +++ b/lib/dnspython/dns/rdtypes/ANY/__init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -27,19 +27,16 @@ __all__ = [ 'HINFO', 'HIP', 'ISDN', - 'KEY', 'LOC', 'MX', 'NS', 'NSEC', 'NSEC3', 'NSEC3PARAM', - 'NXT', 'PTR', 'RP', 'RRSIG', 'RT', - 'SIG', 'SOA', 'SPF', 'SSHFP', diff --git a/lib/dnspython/dns/rdtypes/IN/A.py b/lib/dnspython/dns/rdtypes/IN/A.py index e05f204a2f..372d333226 100644 --- a/lib/dnspython/dns/rdtypes/IN/A.py +++ b/lib/dnspython/dns/rdtypes/IN/A.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/IN/AAAA.py b/lib/dnspython/dns/rdtypes/IN/AAAA.py index 2d812d39eb..e131bd5070 100644 --- a/lib/dnspython/dns/rdtypes/IN/AAAA.py +++ b/lib/dnspython/dns/rdtypes/IN/AAAA.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/IN/APL.py b/lib/dnspython/dns/rdtypes/IN/APL.py index 7412c02d30..260fd6f39f 100644 --- a/lib/dnspython/dns/rdtypes/IN/APL.py +++ b/lib/dnspython/dns/rdtypes/IN/APL.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -131,7 +131,7 @@ class APL(dns.rdata.Rdata): rdlen -= 4 if rdlen < afdlen: raise dns.exception.FormError - address = wire[current : current + afdlen] + address = wire[current : current + afdlen].unwrap() l = len(address) if header[0] == 1: if l < 4: diff --git a/lib/dnspython/dns/rdtypes/IN/DHCID.py b/lib/dnspython/dns/rdtypes/IN/DHCID.py index 2d35234bf0..5524beadd1 100644 --- a/lib/dnspython/dns/rdtypes/IN/DHCID.py +++ b/lib/dnspython/dns/rdtypes/IN/DHCID.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, 2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -51,7 +51,7 @@ class DHCID(dns.rdata.Rdata): file.write(self.data) def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): - data = wire[current : current + rdlen] + data = wire[current : current + rdlen].unwrap() return cls(rdclass, rdtype, data) from_wire = classmethod(from_wire) diff --git a/lib/dnspython/dns/rdtypes/IN/IPSECKEY.py b/lib/dnspython/dns/rdtypes/IN/IPSECKEY.py index 9ab08d881c..d85b6fe993 100644 --- a/lib/dnspython/dns/rdtypes/IN/IPSECKEY.py +++ b/lib/dnspython/dns/rdtypes/IN/IPSECKEY.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, 2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -140,7 +140,7 @@ class IPSECKEY(dns.rdata.Rdata): rdlen -= cused else: raise dns.exception.FormError('invalid IPSECKEY gateway type') - key = wire[current : current + rdlen] + key = wire[current : current + rdlen].unwrap() return cls(rdclass, rdtype, header[0], gateway_type, header[2], gateway, key) diff --git a/lib/dnspython/dns/rdtypes/IN/KX.py b/lib/dnspython/dns/rdtypes/IN/KX.py index 4d8a3a7d6b..c7bd5bbe65 100644 --- a/lib/dnspython/dns/rdtypes/IN/KX.py +++ b/lib/dnspython/dns/rdtypes/IN/KX.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/IN/NAPTR.py b/lib/dnspython/dns/rdtypes/IN/NAPTR.py index a3cca55e1c..7fe043082b 100644 --- a/lib/dnspython/dns/rdtypes/IN/NAPTR.py +++ b/lib/dnspython/dns/rdtypes/IN/NAPTR.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -45,7 +45,7 @@ class NAPTR(dns.rdata.Rdata): __slots__ = ['order', 'preference', 'flags', 'service', 'regexp', 'replacement'] - + def __init__(self, rdclass, rdtype, order, preference, flags, service, regexp, replacement): super(NAPTR, self).__init__(rdclass, rdtype) @@ -76,7 +76,7 @@ class NAPTR(dns.rdata.Rdata): tok.get_eol() return cls(rdclass, rdtype, order, preference, flags, service, regexp, replacement) - + from_text = classmethod(from_text) def to_wire(self, file, compress = None, origin = None): @@ -86,7 +86,7 @@ class NAPTR(dns.rdata.Rdata): _write_string(file, self.service) _write_string(file, self.regexp) self.replacement.to_wire(file, compress, origin) - + def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): (order, preference) = struct.unpack('!HH', wire[current : current + 4]) current += 4 @@ -98,7 +98,7 @@ class NAPTR(dns.rdata.Rdata): rdlen -= 1 if l > rdlen or rdlen < 0: raise dns.exception.FormError - s = wire[current : current + l] + s = wire[current : current + l].unwrap() current += l rdlen -= l strings.append(s) @@ -116,7 +116,7 @@ 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) diff --git a/lib/dnspython/dns/rdtypes/IN/NSAP.py b/lib/dnspython/dns/rdtypes/IN/NSAP.py index 22b9131ccf..216cb0a81a 100644 --- a/lib/dnspython/dns/rdtypes/IN/NSAP.py +++ b/lib/dnspython/dns/rdtypes/IN/NSAP.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -50,7 +50,7 @@ class NSAP(dns.rdata.Rdata): file.write(self.address) def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): - address = wire[current : current + rdlen] + address = wire[current : current + rdlen].unwrap() return cls(rdclass, rdtype, address) from_wire = classmethod(from_wire) diff --git a/lib/dnspython/dns/rdtypes/IN/NSAP_PTR.py b/lib/dnspython/dns/rdtypes/IN/NSAP_PTR.py index 6f591f4ec0..df5b989ac8 100644 --- a/lib/dnspython/dns/rdtypes/IN/NSAP_PTR.py +++ b/lib/dnspython/dns/rdtypes/IN/NSAP_PTR.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/IN/PX.py b/lib/dnspython/dns/rdtypes/IN/PX.py index 0f11290724..1422b83487 100644 --- a/lib/dnspython/dns/rdtypes/IN/PX.py +++ b/lib/dnspython/dns/rdtypes/IN/PX.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -31,7 +31,7 @@ class PX(dns.rdata.Rdata): @see: RFC 2163""" __slots__ = ['preference', 'map822', 'mapx400'] - + def __init__(self, rdclass, rdtype, preference, map822, mapx400): super(PX, self).__init__(rdclass, rdtype) self.preference = preference @@ -42,7 +42,7 @@ class PX(dns.rdata.Rdata): map822 = self.map822.choose_relativity(origin, relativize) mapx400 = self.mapx400.choose_relativity(origin, relativize) return '%d %s %s' % (self.preference, map822, mapx400) - + def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): preference = tok.get_uint16() map822 = tok.get_name() @@ -51,7 +51,7 @@ class PX(dns.rdata.Rdata): mapx400 = mapx400.choose_relativity(origin, relativize) tok.get_eol() return cls(rdclass, rdtype, preference, map822, mapx400) - + from_text = classmethod(from_text) def to_wire(self, file, compress = None, origin = None): @@ -59,7 +59,7 @@ class PX(dns.rdata.Rdata): file.write(pref) self.map822.to_wire(file, None, origin) self.mapx400.to_wire(file, None, origin) - + def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): (preference, ) = struct.unpack('!H', wire[current : current + 2]) current += 2 diff --git a/lib/dnspython/dns/rdtypes/IN/SRV.py b/lib/dnspython/dns/rdtypes/IN/SRV.py index c9c5823381..e101b26bea 100644 --- a/lib/dnspython/dns/rdtypes/IN/SRV.py +++ b/lib/dnspython/dns/rdtypes/IN/SRV.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/IN/WKS.py b/lib/dnspython/dns/rdtypes/IN/WKS.py index 85aafb3d23..04c3054e44 100644 --- a/lib/dnspython/dns/rdtypes/IN/WKS.py +++ b/lib/dnspython/dns/rdtypes/IN/WKS.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -95,7 +95,7 @@ class WKS(dns.rdata.Rdata): protocol, = struct.unpack('!B', wire[current + 4 : current + 5]) current += 5 rdlen -= 5 - bitmap = wire[current : current + rdlen] + bitmap = wire[current : current + rdlen].unwrap() return cls(rdclass, rdtype, address, protocol, bitmap) from_wire = classmethod(from_wire) diff --git a/lib/dnspython/dns/rdtypes/IN/__init__.py b/lib/dnspython/dns/rdtypes/IN/__init__.py index ab931296ec..24cf1ece4e 100644 --- a/lib/dnspython/dns/rdtypes/IN/__init__.py +++ b/lib/dnspython/dns/rdtypes/IN/__init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/__init__.py b/lib/dnspython/dns/rdtypes/__init__.py index 13282be73a..49db5a3776 100644 --- a/lib/dnspython/dns/rdtypes/__init__.py +++ b/lib/dnspython/dns/rdtypes/__init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -20,6 +20,4 @@ __all__ = [ 'IN', 'mxbase', 'nsbase', - 'sigbase', - 'keybase', ] diff --git a/lib/dnspython/dns/rdtypes/dsbase.py b/lib/dnspython/dns/rdtypes/dsbase.py index aa46403a5f..6f5559a7e4 100644 --- a/lib/dnspython/dns/rdtypes/dsbase.py +++ b/lib/dnspython/dns/rdtypes/dsbase.py @@ -1,4 +1,4 @@ -# Copyright (C) 2010 Nominum, Inc. +# Copyright (C) 2010, 2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -76,7 +76,7 @@ class DSBase(dns.rdata.Rdata): header = struct.unpack("!HBB", wire[current : current + 4]) current += 4 rdlen -= 4 - digest = wire[current : current + rdlen] + digest = wire[current : current + rdlen].unwrap() return cls(rdclass, rdtype, header[0], header[1], header[2], digest) from_wire = classmethod(from_wire) diff --git a/lib/dnspython/dns/rdtypes/keybase.py b/lib/dnspython/dns/rdtypes/keybase.py deleted file mode 100644 index 75c9272670..0000000000 --- a/lib/dnspython/dns/rdtypes/keybase.py +++ /dev/null @@ -1,149 +0,0 @@ -# Copyright (C) 2004-2007, 2009, 2010 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import struct - -import dns.exception -import dns.dnssec -import dns.rdata - -_flags_from_text = { - 'NOCONF': (0x4000, 0xC000), - 'NOAUTH': (0x8000, 0xC000), - 'NOKEY': (0xC000, 0xC000), - 'FLAG2': (0x2000, 0x2000), - 'EXTEND': (0x1000, 0x1000), - 'FLAG4': (0x0800, 0x0800), - 'FLAG5': (0x0400, 0x0400), - 'USER': (0x0000, 0x0300), - 'ZONE': (0x0100, 0x0300), - 'HOST': (0x0200, 0x0300), - 'NTYP3': (0x0300, 0x0300), - 'FLAG8': (0x0080, 0x0080), - 'FLAG9': (0x0040, 0x0040), - 'FLAG10': (0x0020, 0x0020), - 'FLAG11': (0x0010, 0x0010), - 'SIG0': (0x0000, 0x000f), - 'SIG1': (0x0001, 0x000f), - 'SIG2': (0x0002, 0x000f), - 'SIG3': (0x0003, 0x000f), - 'SIG4': (0x0004, 0x000f), - 'SIG5': (0x0005, 0x000f), - 'SIG6': (0x0006, 0x000f), - 'SIG7': (0x0007, 0x000f), - 'SIG8': (0x0008, 0x000f), - 'SIG9': (0x0009, 0x000f), - 'SIG10': (0x000a, 0x000f), - 'SIG11': (0x000b, 0x000f), - 'SIG12': (0x000c, 0x000f), - 'SIG13': (0x000d, 0x000f), - 'SIG14': (0x000e, 0x000f), - 'SIG15': (0x000f, 0x000f), - } - -_protocol_from_text = { - 'NONE' : 0, - 'TLS' : 1, - 'EMAIL' : 2, - 'DNSSEC' : 3, - 'IPSEC' : 4, - 'ALL' : 255, - } - -class KEYBase(dns.rdata.Rdata): - """KEY-like record base - - @ivar flags: the key flags - @type flags: int - @ivar protocol: the protocol for which this key may be used - @type protocol: int - @ivar algorithm: the algorithm used for the key - @type algorithm: int - @ivar key: the public key - @type key: string""" - - __slots__ = ['flags', 'protocol', 'algorithm', 'key'] - - def __init__(self, rdclass, rdtype, flags, protocol, algorithm, key): - super(KEYBase, self).__init__(rdclass, rdtype) - self.flags = flags - self.protocol = protocol - self.algorithm = algorithm - self.key = key - - def to_text(self, origin=None, relativize=True, **kw): - return '%d %d %d %s' % (self.flags, self.protocol, self.algorithm, - dns.rdata._base64ify(self.key)) - - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): - flags = tok.get_string() - if flags.isdigit(): - flags = int(flags) - else: - flag_names = flags.split('|') - flags = 0 - for flag in flag_names: - v = _flags_from_text.get(flag) - if v is None: - raise dns.exception.SyntaxError('unknown flag %s' % flag) - flags &= ~v[1] - flags |= v[0] - protocol = tok.get_string() - if protocol.isdigit(): - protocol = int(protocol) - else: - protocol = _protocol_from_text.get(protocol) - if protocol is None: - raise dns.exception.SyntaxError('unknown protocol %s' % protocol) - - algorithm = dns.dnssec.algorithm_from_text(tok.get_string()) - chunks = [] - while 1: - t = tok.get().unescape() - if t.is_eol_or_eof(): - break - if not t.is_identifier(): - raise dns.exception.SyntaxError - chunks.append(t.value) - b64 = ''.join(chunks) - key = b64.decode('base64_codec') - return cls(rdclass, rdtype, flags, protocol, algorithm, key) - - from_text = classmethod(from_text) - - def to_wire(self, file, compress = None, origin = None): - header = struct.pack("!HBB", self.flags, self.protocol, self.algorithm) - file.write(header) - file.write(self.key) - - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): - if rdlen < 4: - raise dns.exception.FormError - header = struct.unpack('!HBB', wire[current : current + 4]) - current += 4 - rdlen -= 4 - key = wire[current : current + rdlen] - return cls(rdclass, rdtype, header[0], header[1], header[2], - key) - - 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 diff --git a/lib/dnspython/dns/rdtypes/mxbase.py b/lib/dnspython/dns/rdtypes/mxbase.py index 5e3515bec4..abc6a9ed5b 100644 --- a/lib/dnspython/dns/rdtypes/mxbase.py +++ b/lib/dnspython/dns/rdtypes/mxbase.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/nsbase.py b/lib/dnspython/dns/rdtypes/nsbase.py index 7cdb2a0289..fbd5ef1e51 100644 --- a/lib/dnspython/dns/rdtypes/nsbase.py +++ b/lib/dnspython/dns/rdtypes/nsbase.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, diff --git a/lib/dnspython/dns/rdtypes/sigbase.py b/lib/dnspython/dns/rdtypes/sigbase.py deleted file mode 100644 index ccb6dd69ae..0000000000 --- a/lib/dnspython/dns/rdtypes/sigbase.py +++ /dev/null @@ -1,168 +0,0 @@ -# Copyright (C) 2004-2007, 2009, 2010 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import calendar -import struct -import time - -import dns.dnssec -import dns.exception -import dns.rdata -import dns.rdatatype - -class BadSigTime(dns.exception.DNSException): - """Raised when a SIG or RRSIG RR's time cannot be parsed.""" - pass - -def sigtime_to_posixtime(what): - if len(what) != 14: - raise BadSigTime - year = int(what[0:4]) - month = int(what[4:6]) - day = int(what[6:8]) - hour = int(what[8:10]) - minute = int(what[10:12]) - second = int(what[12:14]) - return calendar.timegm((year, month, day, hour, minute, second, - 0, 0, 0)) - -def posixtime_to_sigtime(what): - return time.strftime('%Y%m%d%H%M%S', time.gmtime(what)) - -class SIGBase(dns.rdata.Rdata): - """SIG-like record base - - @ivar type_covered: the rdata type this signature covers - @type type_covered: int - @ivar algorithm: the algorithm used for the sig - @type algorithm: int - @ivar labels: number of labels - @type labels: int - @ivar original_ttl: the original TTL - @type original_ttl: long - @ivar expiration: signature expiration time - @type expiration: long - @ivar inception: signature inception time - @type inception: long - @ivar key_tag: the key tag - @type key_tag: int - @ivar signer: the signer - @type signer: dns.name.Name object - @ivar signature: the signature - @type signature: string""" - - __slots__ = ['type_covered', 'algorithm', 'labels', 'original_ttl', - 'expiration', 'inception', 'key_tag', 'signer', - 'signature'] - - def __init__(self, rdclass, rdtype, type_covered, algorithm, labels, - original_ttl, expiration, inception, key_tag, signer, - signature): - super(SIGBase, self).__init__(rdclass, rdtype) - self.type_covered = type_covered - self.algorithm = algorithm - self.labels = labels - self.original_ttl = original_ttl - self.expiration = expiration - self.inception = inception - self.key_tag = key_tag - self.signer = signer - self.signature = signature - - def covers(self): - return self.type_covered - - def to_text(self, origin=None, relativize=True, **kw): - return '%s %d %d %d %s %s %d %s %s' % ( - dns.rdatatype.to_text(self.type_covered), - self.algorithm, - self.labels, - self.original_ttl, - posixtime_to_sigtime(self.expiration), - posixtime_to_sigtime(self.inception), - self.key_tag, - self.signer, - dns.rdata._base64ify(self.signature) - ) - - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): - type_covered = dns.rdatatype.from_text(tok.get_string()) - algorithm = dns.dnssec.algorithm_from_text(tok.get_string()) - labels = tok.get_int() - original_ttl = tok.get_ttl() - expiration = sigtime_to_posixtime(tok.get_string()) - inception = sigtime_to_posixtime(tok.get_string()) - key_tag = tok.get_int() - signer = tok.get_name() - signer = signer.choose_relativity(origin, relativize) - chunks = [] - while 1: - t = tok.get().unescape() - if t.is_eol_or_eof(): - break - if not t.is_identifier(): - raise dns.exception.SyntaxError - chunks.append(t.value) - b64 = ''.join(chunks) - signature = b64.decode('base64_codec') - return cls(rdclass, rdtype, type_covered, algorithm, labels, - original_ttl, expiration, inception, key_tag, signer, - signature) - - from_text = classmethod(from_text) - - def to_wire(self, file, compress = None, origin = None): - header = struct.pack('!HBBIIIH', self.type_covered, - self.algorithm, self.labels, - self.original_ttl, self.expiration, - self.inception, self.key_tag) - file.write(header) - self.signer.to_wire(file, None, origin) - file.write(self.signature) - - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): - header = struct.unpack('!HBBIIIH', wire[current : current + 18]) - current += 18 - rdlen -= 18 - (signer, cused) = dns.name.from_wire(wire[: current + rdlen], current) - current += cused - rdlen -= cused - if not origin is None: - signer = signer.relativize(origin) - signature = wire[current : current + rdlen] - return cls(rdclass, rdtype, header[0], header[1], header[2], - header[3], header[4], header[5], header[6], signer, - signature) - - from_wire = classmethod(from_wire) - - def choose_relativity(self, origin = None, relativize = True): - self.signer = self.signer.choose_relativity(origin, relativize) - - def _cmp(self, other): - hs = struct.pack('!HBBIIIH', self.type_covered, - self.algorithm, self.labels, - self.original_ttl, self.expiration, - self.inception, self.key_tag) - ho = struct.pack('!HBBIIIH', other.type_covered, - other.algorithm, other.labels, - other.original_ttl, other.expiration, - other.inception, other.key_tag) - v = cmp(hs, ho) - if v == 0: - v = cmp(self.signer, other.signer) - if v == 0: - v = cmp(self.signature, other.signature) - return v diff --git a/lib/dnspython/dns/rdtypes/txtbase.py b/lib/dnspython/dns/rdtypes/txtbase.py index 43db2a48c0..580f056ea0 100644 --- a/lib/dnspython/dns/rdtypes/txtbase.py +++ b/lib/dnspython/dns/rdtypes/txtbase.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, 2007, 2009, 2010 Nominum, Inc. +# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, @@ -75,7 +75,7 @@ class TXTBase(dns.rdata.Rdata): rdlen -= 1 if l > rdlen: raise dns.exception.FormError - s = wire[current : current + l] + s = wire[current : current + l].unwrap() current += l rdlen -= l strings.append(s) -- cgit