From 220f5a8de37dd843219cc3059ee9eaac36e8f8d9 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Fri, 3 Nov 2006 23:29:19 +0000 Subject: [PATCH] add DHCID --- ChangeLog | 4 +++ dns/rdatatype.py | 2 ++ dns/rdtypes/IN/DHCID.py | 60 ++++++++++++++++++++++++++++++++++++++ dns/rdtypes/IN/__init__.py | 3 +- tests/example | 6 ++++ tests/example1.good | 3 ++ tests/example2.good | 3 ++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 dns/rdtypes/IN/DHCID.py diff --git a/ChangeLog b/ChangeLog index fc865a47..eb21452e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-11-03 Bob Halley + + * dns/rdtypes/IN/DHCID.py: Added support for the DHCID RR type. + 2006-11-02 Bob Halley * dns/query.py (udp): Messages from unexpected sources can now be diff --git a/dns/rdatatype.py b/dns/rdatatype.py index db4e353e..19e8acb1 100644 --- a/dns/rdatatype.py +++ b/dns/rdatatype.py @@ -75,6 +75,7 @@ IPSECKEY = 45 RRSIG = 46 NSEC = 47 DNSKEY = 48 +DHCID = 49 SPF = 99 UNSPEC = 103 TKEY = 249 @@ -131,6 +132,7 @@ _by_text = { 'RRSIG' : RRSIG, 'NSEC' : NSEC, 'DNSKEY' : DNSKEY, + 'DHCID' : DHCID, 'SPF' : SPF, 'UNSPEC' : UNSPEC, 'TKEY' : TKEY, diff --git a/dns/rdtypes/IN/DHCID.py b/dns/rdtypes/IN/DHCID.py new file mode 100644 index 00000000..a5fb69fd --- /dev/null +++ b/dns/rdtypes/IN/DHCID.py @@ -0,0 +1,60 @@ +# Copyright (C) 2006 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 + +class DHCID(dns.rdata.Rdata): + """DHCID record + + @ivar data: the data (the content of the RR is opaque as far as the + DNS is concerned) + @type data: string + @see: RFC 4701""" + + __slots__ = ['data'] + + def __init__(self, rdclass, rdtype, data): + super(DHCID, self).__init__(rdclass, rdtype) + self.data = data + + def to_text(self, origin=None, relativize=True, **kw): + return dns.rdata._base64ify(self.data) + + def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): + chunks = [] + while 1: + t = tok.get() + if t[0] == dns.tokenizer.EOL or t[0] == dns.tokenizer.EOF: + break + if t[0] != dns.tokenizer.IDENTIFIER: + raise dns.exception.SyntaxError + chunks.append(t[1]) + b64 = ''.join(chunks) + data = b64.decode('base64_codec') + return cls(rdclass, rdtype, data) + + from_text = classmethod(from_text) + + def to_wire(self, file, compress = None, origin = None): + file.write(self.data) + + def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): + data = wire[current : current + rdlen] + return cls(rdclass, rdtype, data) + + from_wire = classmethod(from_wire) + + def _cmp(self, other): + return cmp(self.data, other.data) diff --git a/dns/rdtypes/IN/__init__.py b/dns/rdtypes/IN/__init__.py index fcc63b59..ef1cfa12 100644 --- a/dns/rdtypes/IN/__init__.py +++ b/dns/rdtypes/IN/__init__.py @@ -19,11 +19,12 @@ __all__ = [ 'A', 'AAAA', 'APL', + 'DHCID', 'KX', - 'PX', 'NAPTR', 'NSAP', 'NSAP_PTR', + 'PX', 'SRV', 'WKS', ] diff --git a/tests/example b/tests/example index 0036afb8..0e31d472 100644 --- a/tests/example +++ b/tests/example @@ -69,6 +69,12 @@ cname03 CNAME . $TTL 300 ; 5 minutes d A 73.80.65.49 $TTL 3600 ; 1 hour +dhcid01 DHCID ( AAIBY2/AuCccgoJbsaxcQc9TUapptP69l + OjxfNuVAA2kjEA= ) +dhcid02 DHCID ( AAEBOSD+XR3Os/0LozeXVqcNc7FwCfQdW + L3b/NaiUDlW2No= ) +dhcid03 DHCID ( AAABxLmlskllE0MVjd57zHcWmEH3pCQ6V + ytcKD//7es/deY= ) dname01 DNAME dname-target. dname02 DNAME dname-target dname03 DNAME . diff --git a/tests/example1.good b/tests/example1.good index f322a275..5ec1d6cf 100644 --- a/tests/example1.good +++ b/tests/example1.good @@ -19,6 +19,9 @@ cname01 3600 IN CNAME cname-target. cname02 3600 IN CNAME cname-target cname03 3600 IN CNAME . d 300 IN A 73.80.65.49 +dhcid01 3600 IN DHCID AAIBY2/AuCccgoJbsaxcQc9TUapptP69 lOjxfNuVAA2kjEA= +dhcid02 3600 IN DHCID AAEBOSD+XR3Os/0LozeXVqcNc7FwCfQd WL3b/NaiUDlW2No= +dhcid03 3600 IN DHCID AAABxLmlskllE0MVjd57zHcWmEH3pCQ6 VytcKD//7es/deY= dname01 3600 IN DNAME dname-target. dname02 3600 IN DNAME dname-target dname03 3600 IN DNAME . diff --git a/tests/example2.good b/tests/example2.good index 5e52af12..914accb3 100644 --- a/tests/example2.good +++ b/tests/example2.good @@ -19,6 +19,9 @@ cname01.example. 3600 IN CNAME cname-target. cname02.example. 3600 IN CNAME cname-target.example. cname03.example. 3600 IN CNAME . d.example. 300 IN A 73.80.65.49 +dhcid01.example. 3600 IN DHCID AAIBY2/AuCccgoJbsaxcQc9TUapptP69 lOjxfNuVAA2kjEA= +dhcid02.example. 3600 IN DHCID AAEBOSD+XR3Os/0LozeXVqcNc7FwCfQd WL3b/NaiUDlW2No= +dhcid03.example. 3600 IN DHCID AAABxLmlskllE0MVjd57zHcWmEH3pCQ6 VytcKD//7es/deY= dname01.example. 3600 IN DNAME dname-target. dname02.example. 3600 IN DNAME dname-target.example. dname03.example. 3600 IN DNAME . -- 2.47.3