From: Mark Wooding Date: Thu, 11 May 2017 09:42:15 +0000 (+0100) Subject: catacomb/__init__.py: Fix up cipher etc. names better. X-Git-Tag: 1.1.2~1 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb-python/commitdiff_plain/837fa4850257bc8cc06f7b59937078d2607c1202 catacomb/__init__.py: Fix up cipher etc. names better. Now `sha512/256', for example, will have the right name. --- diff --git a/catacomb/__init__.py b/catacomb/__init__.py index 120ef11..f79b4d2 100644 --- a/catacomb/__init__.py +++ b/catacomb/__init__.py @@ -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