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