1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import struct
17
18 import dns.exception
19 import dns.rdata
20 import dns.tokenizer
21
22
23 -class CAA(dns.rdata.Rdata):
24
25 """CAA (Certification Authority Authorization) record
26
27 @ivar flags: the flags
28 @type flags: int
29 @ivar tag: the tag
30 @type tag: string
31 @ivar value: the value
32 @type value: string
33 @see: RFC 6844"""
34
35 __slots__ = ['flags', 'tag', 'value']
36
37 - def __init__(self, rdclass, rdtype, flags, tag, value):
42
43 - def to_text(self, origin=None, relativize=True, **kw):
44 return '%u %s "%s"' % (self.flags,
45 dns.rdata._escapify(self.tag),
46 dns.rdata._escapify(self.value))
47
48 @classmethod
49 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
50 flags = tok.get_uint8()
51 tag = tok.get_string().encode()
52 if len(tag) > 255:
53 raise dns.exception.SyntaxError("tag too long")
54 if not tag.isalnum():
55 raise dns.exception.SyntaxError("tag is not alphanumeric")
56 value = tok.get_string().encode()
57 return cls(rdclass, rdtype, flags, tag, value)
58
59 - def to_wire(self, file, compress=None, origin=None):
60 file.write(struct.pack('!B', self.flags))
61 l = len(self.tag)
62 assert l < 256
63 file.write(struct.pack('!B', l))
64 file.write(self.tag)
65 file.write(self.value)
66
67 @classmethod
68 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
69 (flags, l) = struct.unpack('!BB', wire[current: current + 2])
70 current += 2
71 tag = wire[current: current + l]
72 value = wire[current + l:current + rdlen - 2]
73 return cls(rdclass, rdtype, flags, tag, value)
74