Package dns :: Module tsigkeyring
[hide private]
[frames] | no frames]

Source Code for Module dns.tsigkeyring

 1  # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license 
 2   
 3  # Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. 
 4  # 
 5  # Permission to use, copy, modify, and distribute this software and its 
 6  # documentation for any purpose with or without fee is hereby granted, 
 7  # provided that the above copyright notice and this permission notice 
 8  # appear in all copies. 
 9  # 
10  # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES 
11  # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 
12  # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR 
13  # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
14  # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
15  # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 
16  # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
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