1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """A place to store TSIG keys."""
19
20 from dns._compat import maybe_decode, maybe_encode
21
22 import base64
23
24 import dns.name
25
26
27 -def from_text(textring):
28 """Convert a dictionary containing (textual DNS name, base64 secret) pairs
29 into a binary keyring which has (dns.name.Name, binary secret) pairs.
30 @rtype: dict"""
31
32 keyring = {}
33 for keytext in textring:
34 keyname = dns.name.from_text(keytext)
35 secret = base64.decodestring(maybe_encode(textring[keytext]))
36 keyring[keyname] = secret
37 return keyring
38
39
40 -def to_text(keyring):
41 """Convert a dictionary containing (dns.name.Name, binary secret) pairs
42 into a text keyring which has (textual DNS name, base64 secret) pairs.
43 @rtype: dict"""
44
45 textring = {}
46 for keyname in keyring:
47 keytext = maybe_decode(keyname.to_text())
48 secret = maybe_decode(base64.encodestring(keyring[keyname]))
49 textring[keytext] = secret
50 return textring
51