1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import struct
17 import binascii
18
19 import dns.rdata
20 import dns.rdatatype
21
22
23 -class DSBase(dns.rdata.Rdata):
24
25 """Base class for rdata that is like a DS record
26
27 @ivar key_tag: the key tag
28 @type key_tag: int
29 @ivar algorithm: the algorithm
30 @type algorithm: int
31 @ivar digest_type: the digest type
32 @type digest_type: int
33 @ivar digest: the digest
34 @type digest: int
35 @see: draft-ietf-dnsext-delegation-signer-14.txt"""
36
37 __slots__ = ['key_tag', 'algorithm', 'digest_type', 'digest']
38
39 - def __init__(self, rdclass, rdtype, key_tag, algorithm, digest_type,
40 digest):
46
47 - def to_text(self, origin=None, relativize=True, **kw):
48 return '%d %d %d %s' % (self.key_tag, self.algorithm,
49 self.digest_type,
50 dns.rdata._hexify(self.digest,
51 chunksize=128))
52
53 @classmethod
54 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
55 key_tag = tok.get_uint16()
56 algorithm = tok.get_uint8()
57 digest_type = tok.get_uint8()
58 chunks = []
59 while 1:
60 t = tok.get().unescape()
61 if t.is_eol_or_eof():
62 break
63 if not t.is_identifier():
64 raise dns.exception.SyntaxError
65 chunks.append(t.value.encode())
66 digest = b''.join(chunks)
67 digest = binascii.unhexlify(digest)
68 return cls(rdclass, rdtype, key_tag, algorithm, digest_type,
69 digest)
70
71 - def to_wire(self, file, compress=None, origin=None):
76
77 @classmethod
78 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
79 header = struct.unpack("!HBB", wire[current: current + 4])
80 current += 4
81 rdlen -= 4
82 digest = wire[current: current + rdlen].unwrap()
83 return cls(rdclass, rdtype, header[0], header[1], header[2], digest)
84