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 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):
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):
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