dnspython  1.16.0
About: dnspython is a DNS toolkit (for Python 2.x) that supports almost all record types.
  Fossies Dox: dnspython-1.16.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

tsigkeyring.py
Go to the documentation of this file.
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
dns.name.from_text
def from_text(text, origin=root, idna_codec=None)
Definition: name.py:873
dns.tsigkeyring.to_text
def to_text(keyring)
Definition: tsigkeyring.py:40
dns._compat.maybe_decode
def maybe_decode(x)
Definition: _compat.py:22
dns.name
Definition: name.py:1
dns.tsigkeyring.from_text
def from_text(textring)
Definition: tsigkeyring.py:27
dns._compat.maybe_encode
def maybe_encode(x)
Definition: _compat.py:24
dns._compat
Definition: _compat.py:1