1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import base64
17 import struct
18
19 import dns.exception
20 import dns.dnssec
21 import dns.rdata
22 import dns.util
23
24
25 SEP = 0x0001
26 REVOKE = 0x0080
27 ZONE = 0x0100
28
29 -class DNSKEY(dns.rdata.Rdata):
30 """DNSKEY record
31
32 @ivar flags: the key flags
33 @type flags: int
34 @ivar protocol: the protocol for which this key may be used
35 @type protocol: int
36 @ivar algorithm: the algorithm used for the key
37 @type algorithm: int
38 @ivar key: the public key
39 @type key: string"""
40
41 __slots__ = ['flags', 'protocol', 'algorithm', 'key']
42
43 - def __init__(self, rdclass, rdtype, flags, protocol, algorithm, key):
49
50 - def to_text(self, origin=None, relativize=True, **kw):
51 return '%d %d %d %s' % (self.flags, self.protocol, self.algorithm,
52 dns.rdata._base64ify(self.key))
53
54 @classmethod
55 - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
56 flags = tok.get_uint16()
57 protocol = tok.get_uint8()
58 algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
59 chunks = []
60 while 1:
61 t = tok.get().unescape()
62 if t.is_eol_or_eof():
63 break
64 if not t.is_identifier():
65 raise dns.exception.SyntaxError
66 chunks.append(t.value)
67 b64 = ''.join(chunks)
68 key = base64.b64decode(b64.encode('ascii'))
69 return cls(rdclass, rdtype, flags, protocol, algorithm, key)
70
71 - def to_wire(self, file, compress = None, origin = None):
75
76 @classmethod
77 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
78 if rdlen < 4:
79 raise dns.exception.FormError
80 header = struct.unpack('!HBB', wire[current : current + 4])
81 current += 4
82 rdlen -= 4
83 key = wire[current : current + rdlen].unwrap()
84 return cls(rdclass, rdtype, header[0], header[1], header[2],
85 key)
86
87 - def _cmp(self, other):
94