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)  

dsbase.py
Go to the documentation of this file.
1 # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
2 
3 # Copyright (C) 2010, 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  """Base class for rdata that is like a DS record
28 
29  @ivar key_tag: the key tag
30  @type key_tag: int
31  @ivar algorithm: the algorithm
32  @type algorithm: int
33  @ivar digest_type: the digest type
34  @type digest_type: int
35  @ivar digest: the digest
36  @type digest: int
37  @see: draft-ietf-dnsext-delegation-signer-14.txt"""
38 
39  __slots__ = ['key_tag', 'algorithm', 'digest_type', 'digest']
40 
41  def __init__(self, rdclass, rdtype, key_tag, algorithm, digest_type,
42  digest):
43  super(DSBase, self).__init__(rdclass, rdtype)
44  self.key_tag = key_tag
45  self.algorithm = algorithm
46  self.digest_type = digest_type
47  self.digest = digest
48 
49  def to_text(self, origin=None, relativize=True, **kw):
50  return '%d %d %d %s' % (self.key_tag, self.algorithm,
51  self.digest_type,
53  chunksize=128))
54 
55  @classmethod
56  def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
57  key_tag = tok.get_uint16()
58  algorithm = tok.get_uint8()
59  digest_type = tok.get_uint8()
60  chunks = []
61  while 1:
62  t = tok.get().unescape()
63  if t.is_eol_or_eof():
64  break
65  if not t.is_identifier():
67  chunks.append(t.value.encode())
68  digest = b''.join(chunks)
69  digest = binascii.unhexlify(digest)
70  return cls(rdclass, rdtype, key_tag, algorithm, digest_type,
71  digest)
72 
73  def to_wire(self, file, compress=None, origin=None):
74  header = struct.pack("!HBB", self.key_tag, self.algorithm,
75  self.digest_type)
76  file.write(header)
77  file.write(self.digest)
78 
79  @classmethod
80  def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
81  header = struct.unpack("!HBB", wire[current: current + 4])
82  current += 4
83  rdlen -= 4
84  digest = wire[current: current + rdlen].unwrap()
85  return cls(rdclass, rdtype, header[0], header[1], header[2], digest)
dns.rdtypes.dsbase.DSBase.algorithm
algorithm
Definition: dsbase.py:44
dns.exception.SyntaxError
Definition: exception.py:113
dns.rdtypes.dsbase.DSBase.to_wire
def to_wire(self, file, compress=None, origin=None)
Definition: dsbase.py:73
dns.rdata._hexify
def _hexify(data, chunksize=_hex_chunksize)
Definition: rdata.py:40
dns.rdtypes.dsbase.DSBase.__init__
def __init__(self, rdclass, rdtype, key_tag, algorithm, digest_type, digest)
Definition: dsbase.py:41
dns.rdtypes.dsbase.DSBase.digest_type
digest_type
Definition: dsbase.py:45
dns.rdtypes.dsbase.DSBase.from_wire
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None)
Definition: dsbase.py:80
dns.rdtypes.dsbase.DSBase
Definition: dsbase.py:25
dns.rdtypes.dsbase.DSBase.digest
digest
Definition: dsbase.py:46
dns.rdtypes.dsbase.DSBase.from_text
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True)
Definition: dsbase.py:56
dns.rdata
Definition: rdata.py:1
dns.rdatatype
Definition: rdatatype.py:1
dns.rdtypes.dsbase.DSBase.to_text
def to_text(self, origin=None, relativize=True, **kw)
Definition: dsbase.py:49
dns.rdtypes.dsbase.DSBase.key_tag
key_tag
Definition: dsbase.py:43
dns.rdata.Rdata
Definition: rdata.py:95