diff options
Diffstat (limited to 'passlib/handlers/digests.py')
-rw-r--r-- | passlib/handlers/digests.py | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/passlib/handlers/digests.py b/passlib/handlers/digests.py index e511e16..f1a21bd 100644 --- a/passlib/handlers/digests.py +++ b/passlib/handlers/digests.py @@ -1,20 +1,19 @@ """passlib.handlers.digests - plain hash digests """ -#========================================================= -#imports -#========================================================= -#core +#============================================================================= +# imports +#============================================================================= +# core import hashlib import logging; log = logging.getLogger(__name__) from warnings import warn -#site -#libs +# site +# pkg from passlib.utils import to_native_str, to_bytes, render_bytes, consteq from passlib.utils.compat import bascii_to_str, bytes, unicode, str_to_uascii import passlib.utils.handlers as uh from passlib.utils.md4 import md4 -#pkg -#local +# local __all__ = [ "create_hex_hash", "hex_md4", @@ -24,21 +23,21 @@ __all__ = [ "hex_sha512", ] -#========================================================= -#helpers for hexidecimal hashes -#========================================================= +#============================================================================= +# helpers for hexidecimal hashes +#============================================================================= class HexDigestHash(uh.StaticHandler): "this provides a template for supporting passwords stored as plain hexidecimal hashes" - #========================================================= + #=================================================================== # class attrs - #========================================================= + #=================================================================== _hash_func = None # hash function to use - filled in by create_hex_hash() checksum_size = None # filled in by create_hex_hash() checksum_chars = uh.HEX_CHARS - #========================================================= + #=================================================================== # methods - #========================================================= + #=================================================================== @classmethod def _norm_hash(cls, hash): return hash.lower() @@ -48,18 +47,18 @@ class HexDigestHash(uh.StaticHandler): secret = secret.encode("utf-8") return str_to_uascii(self._hash_func(secret).hexdigest()) - #========================================================= + #=================================================================== # eoc - #========================================================= + #=================================================================== def create_hex_hash(hash, digest_name, module=__name__): - #NOTE: could set digest_name=hash.name for cpython, but not for some other platforms. + # NOTE: could set digest_name=hash.name for cpython, but not for some other platforms. h = hash() name = "hex_" + digest_name return type(name, (HexDigestHash,), dict( name=name, __module__=module, # so ABCMeta won't clobber it - _hash_func=staticmethod(hash), #sometimes it's a function, sometimes not. so wrap it. + _hash_func=staticmethod(hash), # sometimes it's a function, sometimes not. so wrap it. checksum_size=h.digest_size*2, __doc__="""This class implements a plain hexidecimal %s hash, and follows the :ref:`password-hash-api`. @@ -67,9 +66,9 @@ It supports no optional or contextual keywords. """ % (digest_name,) )) -#========================================================= -#predefined handlers -#========================================================= +#============================================================================= +# predefined handlers +#============================================================================= hex_md4 = create_hex_hash(md4, "md4") hex_md5 = create_hex_hash(hashlib.md5, "md5") hex_md5.django_name = "unsalted_md5" @@ -77,9 +76,9 @@ hex_sha1 = create_hex_hash(hashlib.sha1, "sha1") hex_sha256 = create_hex_hash(hashlib.sha256, "sha256") hex_sha512 = create_hex_hash(hashlib.sha512, "sha512") -#========================================================= +#============================================================================= # htdigest -#========================================================= +#============================================================================= class htdigest(uh.PasswordHash): """htdigest hash function. @@ -140,6 +139,6 @@ class htdigest(uh.PasswordHash): cls._norm_hash(config) return cls.encrypt(secret, user, realm, encoding) -#========================================================= -#eof -#========================================================= +#============================================================================= +# eof +#============================================================================= |