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)  

NSEC3PARAM.py
Go to the documentation of this file.
1 # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
2 
3 # Copyright (C) 2004-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.exception
22 import dns.rdata
23 from dns._compat import text_type
24 
25 
27 
28  """NSEC3PARAM record
29 
30  @ivar algorithm: the hash algorithm number
31  @type algorithm: int
32  @ivar flags: the flags
33  @type flags: int
34  @ivar iterations: the number of iterations
35  @type iterations: int
36  @ivar salt: the salt
37  @type salt: string"""
38 
39  __slots__ = ['algorithm', 'flags', 'iterations', 'salt']
40 
41  def __init__(self, rdclass, rdtype, algorithm, flags, iterations, salt):
42  super(NSEC3PARAM, self).__init__(rdclass, rdtype)
43  self.algorithm = algorithm
44  self.flags = flags
45  self.iterations = iterations
46  if isinstance(salt, text_type):
47  self.salt = salt.encode()
48  else:
49  self.salt = salt
50 
51  def to_text(self, origin=None, relativize=True, **kw):
52  if self.salt == b'':
53  salt = '-'
54  else:
55  salt = binascii.hexlify(self.salt).decode()
56  return '%u %u %u %s' % (self.algorithm, self.flags, self.iterations,
57  salt)
58 
59  @classmethod
60  def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
61  algorithm = tok.get_uint8()
62  flags = tok.get_uint8()
63  iterations = tok.get_uint16()
64  salt = tok.get_string()
65  if salt == '-':
66  salt = ''
67  else:
68  salt = binascii.unhexlify(salt.encode())
69  tok.get_eol()
70  return cls(rdclass, rdtype, algorithm, flags, iterations, salt)
71 
72  def to_wire(self, file, compress=None, origin=None):
73  l = len(self.salt)
74  file.write(struct.pack("!BBHB", self.algorithm, self.flags,
75  self.iterations, l))
76  file.write(self.salt)
77 
78  @classmethod
79  def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
80  (algorithm, flags, iterations, slen) = \
81  struct.unpack('!BBHB',
82  wire[current: current + 5])
83  current += 5
84  rdlen -= 5
85  salt = wire[current: current + slen].unwrap()
86  current += slen
87  rdlen -= slen
88  if rdlen != 0:
90  return cls(rdclass, rdtype, algorithm, flags, iterations, salt)
dns.exception.FormError
Definition: exception.py:109
dns.rdtypes.ANY.NSEC3PARAM.NSEC3PARAM.to_wire
def to_wire(self, file, compress=None, origin=None)
Definition: NSEC3PARAM.py:72
dns.rdtypes.ANY.NSEC3PARAM.NSEC3PARAM
Definition: NSEC3PARAM.py:26
dns.rdtypes.ANY.NSEC3PARAM.NSEC3PARAM.from_wire
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None)
Definition: NSEC3PARAM.py:79
dns.rdtypes.ANY.NSEC3PARAM.NSEC3PARAM.__init__
def __init__(self, rdclass, rdtype, algorithm, flags, iterations, salt)
Definition: NSEC3PARAM.py:41
dns.rdtypes.ANY.NSEC3PARAM.NSEC3PARAM.from_text
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True)
Definition: NSEC3PARAM.py:60
dns.rdtypes.ANY.NSEC3PARAM.NSEC3PARAM.iterations
iterations
Definition: NSEC3PARAM.py:45
dns.rdtypes.ANY.NSEC3PARAM.NSEC3PARAM.salt
salt
Definition: NSEC3PARAM.py:47
dns.rdtypes.ANY.NSEC3PARAM.NSEC3PARAM.flags
flags
Definition: NSEC3PARAM.py:44
dns.rdata
Definition: rdata.py:1
dns.rdtypes.ANY.NSEC3PARAM.NSEC3PARAM.to_text
def to_text(self, origin=None, relativize=True, **kw)
Definition: NSEC3PARAM.py:51
dns._compat
Definition: _compat.py:1
dns.rdtypes.ANY.NSEC3PARAM.NSEC3PARAM.algorithm
algorithm
Definition: NSEC3PARAM.py:43
dns.exception
Definition: exception.py:1
dns.rdata.Rdata
Definition: rdata.py:95