From 837fa4850257bc8cc06f7b59937078d2607c1202 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 11 May 2017 10:42:15 +0100 Subject: [PATCH] catacomb/__init__.py: Fix up cipher etc. names better. Now `sha512/256', for example, will have the right name. --- catacomb/__init__.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 -- 2.11.0