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