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

Source Code for Module dns.rdtypes.dsbase

 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 25 -class DSBase(dns.rdata.Rdata):
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, 52 dns.rdata._hexify(self.digest, 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(): 66 raise dns.exception.SyntaxError 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)
86