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

# Source Code for Module dns.rdtypes.ANY.NSEC3PARAM

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