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 DSBase(dns.rdata.Rdata):
23 """Base class for rdata that is like a DS record
24
25 @ivar key_tag: the key tag
26 @type key_tag: int
27 @ivar algorithm: the algorithm
28 @type algorithm: int
29 @ivar digest_type: the digest type
30 @type digest_type: int
31 @ivar digest: the digest
32 @type digest: bytes
33 @see: draft-ietf-dnsext-delegation-signer-14.txt"""
34
35 __slots__ = ['key_tag', 'algorithm', 'digest_type', 'digest']
36
37 - def __init__(self, rdclass, rdtype, key_tag, algorithm, digest_type,
38 digest):
44
45 - def to_text(self, origin=None, relativize=True, **kw):
46 return '%d %d %d %s' % (self.key_tag, self.algorithm,
47 self.digest_type,
48 dns.rdata._hexify(self.digest,
49 chunksize=128))
50
51 @classmethod
52 - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
53 key_tag = tok.get_uint16()
54 algorithm = tok.get_uint8()
55 digest_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)
64 digest = bytes.fromhex(''.join(chunks))
65 return cls(rdclass, rdtype, key_tag, algorithm, digest_type,
66 digest)
67
68 - def to_wire(self, file, compress = None, origin = None):
73
74 @classmethod
75 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
76 header = struct.unpack("!HBB", wire[current : current + 4])
77 current += 4
78 rdlen -= 4
79 digest = wire[current : current + rdlen].unwrap()
80 return cls(rdclass, rdtype, header[0], header[1], header[2], digest)
81
82 - def _cmp(self, other):
91