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 +- 30 files changed, 279 insertions(+), 236 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 (limited to 'lib/dnspython/dns/rdtypes/ANY') 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', -- cgit