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