dnspython  1.16.0
About: dnspython is a DNS toolkit (for Python 2.x) that supports almost all record types.
  Fossies Dox: dnspython-1.16.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

TLSA.py
Go to the documentation of this file.
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 
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,
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():
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)
dns.exception.SyntaxError
Definition: exception.py:113
dns.rdtypes.ANY.TLSA.TLSA.__init__
def __init__(self, rdclass, rdtype, usage, selector, mtype, cert)
Definition: TLSA.py:41
dns.rdtypes.ANY.TLSA.TLSA
Definition: TLSA.py:25
dns.rdtypes.ANY.TLSA.TLSA.from_wire
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None)
Definition: TLSA.py:79
dns.rdata._hexify
def _hexify(data, chunksize=_hex_chunksize)
Definition: rdata.py:40
dns.rdtypes.ANY.TLSA.TLSA.mtype
mtype
Definition: TLSA.py:45
dns.rdtypes.ANY.TLSA.TLSA.to_text
def to_text(self, origin=None, relativize=True, **kw)
Definition: TLSA.py:49
dns.rdtypes.ANY.TLSA.TLSA.selector
selector
Definition: TLSA.py:44
dns.rdtypes.ANY.TLSA.TLSA.from_text
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True)
Definition: TLSA.py:57
dns.rdtypes.ANY.TLSA.TLSA.to_wire
def to_wire(self, file, compress=None, origin=None)
Definition: TLSA.py:73
dns.rdtypes.ANY.TLSA.TLSA.cert
cert
Definition: TLSA.py:46
dns.rdata
Definition: rdata.py:1
dns.rdatatype
Definition: rdatatype.py:1
dns.rdtypes.ANY.TLSA.TLSA.usage
usage
Definition: TLSA.py:43
dns.rdata.Rdata
Definition: rdata.py:95