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

Source Code for Module dns.rdtypes.ANY.SSHFP

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