1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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):
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):
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