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

Source Code for Module dns.rdtypes.ANY.TLSA

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