chiark / gitweb /
Merge branch '1.1.x'
[catacomb-python] / catacomb / __init__.py
index 6fc3725abf51aed1bbce16ab42fabe662e8df029..785838e67eb94830a2358670bcd86049ac0e889c 100644 (file)
@@ -34,6 +34,20 @@ from sys import argv as _argv
 ## For the benefit of the default keyreporter, we need the program na,e.
 _base._ego(_argv[0])
 
+## How to fix a name back into the right identifier.  Alas, the rules are not
+## consistent.
+def _fixname(name):
+
+  ## Hyphens consistently become underscores.
+  name = name.replace('-', '_')
+
+  ## But slashes might become underscores or just vanish.
+  if name.startswith('salsa20'): name = name.translate(None, '/')
+  else: name = name.replace('/', '_')
+
+  ## Done.
+  return name
+
 ## Initialize the module.  Drag in the static methods of the various
 ## classes; create names for the various known crypto algorithms.
 def _init():
@@ -56,9 +70,9 @@ def _init():
         setattr(c, j[plen:], classmethod(b[j]))
   for i in [gcciphers, gchashes, gcmacs, gcprps]:
     for c in i.itervalues():
-      d[c.name.replace('-', '_').translate(None, '/')] = c
+      d[_fixname(c.name)] = c
   for c in gccrands.itervalues():
-    d[c.name.replace('-', '_').translate(None, '/') + 'rand'] = c
+    d[_fixname(c.name + 'rand')] = c
 _init()
 
 ## A handy function for our work: add the methods of a named class to an