Package dns :: Package rdtypes :: Package ANY :: Module TLSA
[hide private]
[frames] | no frames]

Source Code for Module dns.rdtypes.ANY.TLSA

 1  # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license 
 2   
 3  # Copyright (C) 2005-2007, 2009-2011 Nominum, Inc. 
 4  # 
 5  # Permission to use, copy, modify, and distribute this software and its 
 6  # documentation for any purpose with or without fee is hereby granted, 
 7  # provided that the above copyright notice and this permission notice 
 8  # appear in all copies. 
 9  # 
10  # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES 
11  # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 
12  # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR 
13  # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
14  # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
15  # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 
16  # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
17   
18  import struct 
19  import binascii 
20   
21  import dns.rdata 
22  import dns.rdatatype 
23 24 25 -class TLSA(dns.rdata.Rdata):
26 27 """TLSA record 28 29 @ivar usage: The certificate usage 30 @type usage: int 31 @ivar selector: The selector field 32 @type selector: int 33 @ivar mtype: The 'matching type' field 34 @type mtype: int 35 @ivar cert: The 'Certificate Association Data' field 36 @type cert: string 37 @see: RFC 6698""" 38 39 __slots__ = ['usage', 'selector', 'mtype', 'cert'] 40
41 - def __init__(self, rdclass, rdtype, usage, selector, 42 mtype, cert):
43 super(TLSA, self).__init__(rdclass, rdtype) 44 self.usage = usage 45 self.selector = selector 46 self.mtype = mtype 47 self.cert = cert
48
49 - def to_text(self, origin=None, relativize=True, **kw):
50 return '%d %d %d %s' % (self.usage, 51 self.selector, 52 self.mtype, 53 dns.rdata._hexify(self.cert, 54 chunksize=128))
55 56 @classmethod
57 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
58 usage = tok.get_uint8() 59 selector = tok.get_uint8() 60 mtype = tok.get_uint8() 61 cert_chunks = [] 62 while 1: 63 t = tok.get().unescape() 64 if t.is_eol_or_eof(): 65 break 66 if not t.is_identifier(): 67 raise dns.exception.SyntaxError 68 cert_chunks.append(t.value.encode()) 69 cert = b''.join(cert_chunks) 70 cert = binascii.unhexlify(cert) 71 return cls(rdclass, rdtype, usage, selector, mtype, cert)
72
73 - def to_wire(self, file, compress=None, origin=None):
74 header = struct.pack("!BBB", self.usage, self.selector, self.mtype) 75 file.write(header) 76 file.write(self.cert)
77 78 @classmethod
79 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
80 header = struct.unpack("!BBB", wire[current: current + 3]) 81 current += 3 82 rdlen -= 3 83 cert = wire[current: current + rdlen].unwrap() 84 return cls(rdclass, rdtype, header[0], header[1], header[2], cert)
85