1 # Copyright (C) 2003-2007, 2009 Nominum, Inc.
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.
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.
16 """Common DNSSEC-related functions and constants."""
31 _algorithm_by_text = {
37 'DSANSEC3SHA1' : DSANSEC3SHA1,
38 'RSASHA1NSEC3SHA1' : RSASHA1NSEC3SHA1,
39 'RSASHA256' : RSASHA256,
40 'RSASHA512' : RSASHA512,
41 'INDIRECT' : INDIRECT,
42 'PRIVATEDNS' : PRIVATEDNS,
43 'PRIVATEOID' : PRIVATEOID,
46 # We construct the inverse mapping programmatically to ensure that we
47 # cannot make any mistakes (e.g. omissions, cut-and-paste errors) that
48 # would cause the mapping not to be true inverse.
50 _algorithm_by_value = dict([(y, x) for x, y in _algorithm_by_text.iteritems()])
52 class UnknownAlgorithm(Exception):
53 """Raised if an algorithm is unknown."""
56 def algorithm_from_text(text):
57 """Convert text into a DNSSEC algorithm value
60 value = _algorithm_by_text.get(text.upper())
65 def algorithm_to_text(value):
66 """Convert a DNSSEC algorithm value to text
69 text = _algorithm_by_value.get(value)