1
2
3
4
5
6
7
8
9
10
11
12
13
14
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: string
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 fingerprint = bytes.fromhex(tok.get_string())
52 tok.get_eol()
53 return cls(rdclass, rdtype, algorithm, fp_type, fingerprint)
54
55 from_text = classmethod(from_text)
56
57 - def to_wire(self, file, compress = None, origin = None):
58 header = struct.pack("!BB", self.algorithm, self.fp_type)
59 file.write(header)
60 file.write(self.fingerprint)
61
62 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
63 header = struct.unpack("!BB", wire[current : current + 2])
64 current += 2
65 rdlen -= 2
66 fingerprint = wire[current : current + rdlen]
67 return cls(rdclass, rdtype, header[0], header[1], fingerprint)
68
69 from_wire = classmethod(from_wire)
70
71 - def _cmp(self, other):
72 hs = struct.pack("!BB", self.algorithm, self.fp_type)
73 ho = struct.pack("!BB", other.algorithm, other.fp_type)
74 v = dns.util.cmp(hs, ho)
75 if v == 0:
76 v = dns.util.cmp(self.fingerprint, other.fingerprint)
77 return v
78