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

Source Code for Module dns.dnssec

 1  # Copyright (C) 2003-2007, 2009 Nominum, Inc. 
 2  # 
 3  # Permission to use, copy, modify, and distribute this software and its 
 4  # documentation for any purpose with or without fee is hereby granted, 
 5  # provided that the above copyright notice and this permission notice 
 6  # appear in all copies. 
 7  # 
 8  # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES 
 9  # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 
10  # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR 
11  # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
12  # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
13  # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 
14  # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
15   
16  """Common DNSSEC-related functions and constants.""" 
17   
18  RSAMD5 = 1 
19  DH = 2 
20  DSA = 3 
21  ECC = 4 
22  RSASHA1 = 5 
23  DSANSEC3SHA1 = 6 
24  RSASHA1NSEC3SHA1 = 7 
25  INDIRECT = 252 
26  PRIVATEDNS = 253 
27  PRIVATEOID = 254 
28   
29  _algorithm_by_text = { 
30      'RSAMD5' : RSAMD5, 
31      'DH' : DH, 
32      'DSA' : DSA, 
33      'ECC' : ECC, 
34      'INDIRECT' : INDIRECT, 
35      'PRIVATEDNS' : PRIVATEDNS, 
36      'PRIVATEOID' : PRIVATEOID, 
37      } 
38   
39  # We construct the inverse mapping programmatically to ensure that we 
40  # cannot make any mistakes (e.g. omissions, cut-and-paste errors) that 
41  # would cause the mapping not to be true inverse. 
42   
43  _algorithm_by_value = dict([(y, x) for x, y in _algorithm_by_text.iteritems()]) 
44   
45 -class UnknownAlgorithm(Exception):
46 """Raised if an algorithm is unknown.""" 47 pass
48
49 -def algorithm_from_text(text):
50 """Convert text into a DNSSEC algorithm value 51 @rtype: int""" 52 53 value = _algorithm_by_text.get(text.upper()) 54 if value is None: 55 value = int(text) 56 return value
57
58 -def algorithm_to_text(value):
59 """Convert a DNSSEC algorithm value to text 60 @rtype: string""" 61 62 text = _algorithm_by_value.get(value) 63 if text is None: 64 text = str(value) 65 return text
66