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

Source Code for Module dns.rdtypes.ANY.SSHFP

 1  # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license 
 2   
 3  # Copyright (C) 2005-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.rdata 
22  import dns.rdatatype 
23 24 25 -class SSHFP(dns.rdata.Rdata):
26 27 """SSHFP record 28 29 @ivar algorithm: the algorithm 30 @type algorithm: int 31 @ivar fp_type: the digest type 32 @type fp_type: int 33 @ivar fingerprint: the fingerprint 34 @type fingerprint: string 35 @see: draft-ietf-secsh-dns-05.txt""" 36 37 __slots__ = ['algorithm', 'fp_type', 'fingerprint'] 38
39 - def __init__(self, rdclass, rdtype, algorithm, fp_type, 40 fingerprint):
41 super(SSHFP, self).__init__(rdclass, rdtype) 42 self.algorithm = algorithm 43 self.fp_type = fp_type 44 self.fingerprint = fingerprint
45
46 - def to_text(self, origin=None, relativize=True, **kw):
47 return '%d %d %s' % (self.algorithm, 48 self.fp_type, 49 dns.rdata._hexify(self.fingerprint, 50 chunksize=128))
51 52 @classmethod
53 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
54 algorithm = tok.get_uint8() 55 fp_type = tok.get_uint8() 56 chunks = [] 57 while 1: 58 t = tok.get().unescape() 59 if t.is_eol_or_eof(): 60 break 61 if not t.is_identifier(): 62 raise dns.exception.SyntaxError 63 chunks.append(t.value.encode()) 64 fingerprint = b''.join(chunks) 65 fingerprint = binascii.unhexlify(fingerprint) 66 return cls(rdclass, rdtype, algorithm, fp_type, fingerprint)
67
68 - def to_wire(self, file, compress=None, origin=None):
69 header = struct.pack("!BB", self.algorithm, self.fp_type) 70 file.write(header) 71 file.write(self.fingerprint)
72 73 @classmethod
74 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
75 header = struct.unpack("!BB", wire[current: current + 2]) 76 current += 2 77 rdlen -= 2 78 fingerprint = wire[current: current + rdlen].unwrap() 79 return cls(rdclass, rdtype, header[0], header[1], fingerprint)
80