1
# Copyright (C) 2005-2007, 2009-2011 Nominum, Inc.
3
# Permission to use, copy, modify, and distribute this software and its
4
# documentation for any purpose with or without fee is hereby granted,
5
# provided that the above copyright notice and this permission notice
6
# appear in all copies.
8
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
9
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
11
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
class TLSA(dns.rdata.Rdata):
24
@ivar usage: The certificate usage
26
@ivar selector: The selector field
28
@ivar mtype: The 'matching type' field
30
@ivar cert: The 'Certificate Association Data' field
34
__slots__ = ['usage', 'selector', 'mtype', 'cert']
36
def __init__(self, rdclass, rdtype, usage, selector,
38
super(TLSA, self).__init__(rdclass, rdtype)
40
self.selector = selector
44
def to_text(self, origin=None, relativize=True, **kw):
45
return '%d %d %d %s' % (self.usage,
48
dns.rdata._hexify(self.cert,
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()
57
t = tok.get().unescape()
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)
67
from_text = classmethod(from_text)
69
def to_wire(self, file, compress = None, origin = None):
70
header = struct.pack("!BBB", self.usage, self.selector, self.mtype)
74
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
75
header = struct.unpack("!BBB", wire[current : current + 3])
78
cert = wire[current : current + rdlen].unwrap()
79
return cls(rdclass, rdtype, header[0], header[1], header[2], cert)
81
from_wire = classmethod(from_wire)
83
def _cmp(self, other):
84
hs = struct.pack("!BBB", self.usage, self.selector, self.mtype)
85
ho = struct.pack("!BBB", other.usage, other.selector, other.mtype)
88
v = cmp(self.cert, other.cert)