1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import struct
17
18 import dns.rdata
19 import dns.rdatatype
20
21 -class TLSA(dns.rdata.Rdata):
22 """TLSA record
23
24 @ivar usage: The certificate usage
25 @type usage: int
26 @ivar selector: The selector field
27 @type selector: int
28 @ivar mtype: The 'matching type' field
29 @type mtype: int
30 @ivar cert: The 'Certificate Association Data' field
31 @type cert: string
32 @see: RFC 6698"""
33
34 __slots__ = ['usage', 'selector', 'mtype', 'cert']
35
36 - def __init__(self, rdclass, rdtype, usage, selector,
37 mtype, cert):
43
44 - def to_text(self, origin=None, relativize=True, **kw):
45 return '%d %d %d %s' % (self.usage,
46 self.selector,
47 self.mtype,
48 dns.rdata._hexify(self.cert,
49 chunksize=128))
50
51 - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
52 usage = tok.get_uint8()
53 selector = tok.get_uint8()
54 mtype = tok.get_uint8()
55 cert_chunks = []
56 while 1:
57 t = tok.get().unescape()
58 if t.is_eol_or_eof():
59 break
60 if not t.is_identifier():
61 raise dns.exception.SyntaxError
62 cert_chunks.append(t.value)
63 cert = ''.join(cert_chunks)
64 cert = cert.decode('hex_codec')
65 return cls(rdclass, rdtype, usage, selector, mtype, cert)
66
67 from_text = classmethod(from_text)
68
69 - def to_wire(self, file, compress = None, origin = None):
70 header = struct.pack("!BBB", self.usage, self.selector, self.mtype)
71 file.write(header)
72 file.write(self.cert)
73
74 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
75 header = struct.unpack("!BBB", wire[current : current + 3])
76 current += 3
77 rdlen -= 3
78 cert = wire[current : current + rdlen].unwrap()
79 return cls(rdclass, rdtype, header[0], header[1], header[2], cert)
80
81 from_wire = classmethod(from_wire)
82
83 - def _cmp(self, other):
90