diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2016-06-13 16:21:07 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2016-06-13 16:21:07 -0400 |
commit | d9ef8678371662f000ce3b3d0d1a038b38e3b8d9 (patch) | |
tree | 9671bdf710030f2f6679ac8be574327a98a65aeb /passlib/handlers/misc.py | |
parent | f615072748c1dca7646c513f6b8e790d0cd6b912 (diff) | |
download | passlib-d9ef8678371662f000ce3b3d0d1a038b38e3b8d9.tar.gz |
handler.genconfig() / .genhash() deprecated entirely
after further consideration (while implementing a handler for argon2),
decided that rolling .genconfig() and .genhash() into the .hash() method
(as was done in rev 1f7421b35b75) put too much complexity into the .hash() method.
this commit walks back those portions of rev 1f7421b35b75 -- .genconfig()
and .genhash() are now implemented for each handler directly.
however, going a little further and completely deprecating .genconfig()
and .genhash() support entirely -- decided there's no need for them in
the public api whatsoever. apps shouldn't need/use them, and the unittests
can use their own workarounds.
* removed "config" keyword from handler.hash() ifc
* removed support for config=None from handler.genhash() -- nothing should use it
now that handler.genconfig() always returns a string.
* marked .genhash() and .genconfig() as completely deprecated, w/ no alternative
* uts: factored out calls which need config only into a .do_stub_encrypt() helper,
as replacement for internal uses of .genconfig()
Diffstat (limited to 'passlib/handlers/misc.py')
-rw-r--r-- | passlib/handlers/misc.py | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/passlib/handlers/misc.py b/passlib/handlers/misc.py index b342905..150e8b1 100644 --- a/passlib/handlers/misc.py +++ b/passlib/handlers/misc.py @@ -147,14 +147,8 @@ class unix_disabled(uh.MinimalHandler): return False @classmethod - def hash(cls, secret, config=None, marker=None): + def hash(cls, secret, marker=None): uh.validate_secret(secret) - if not (config is None or config is True): - # we want to preserve the existing str, - # since it might contain a disabled password hash ("!" + hash) - if not cls.identify(config): - raise uh.exc.InvalidHashError(cls) - return to_native_str(config, param="config") # if None or empty string, replace with marker if marker: if not cls.identify(marker): @@ -164,6 +158,18 @@ class unix_disabled(uh.MinimalHandler): assert marker and cls.identify(marker) return to_native_str(marker, param="marker") + @uh.deprecated_method(deprecated="1.7", removed="2.0") + @classmethod + def genhash(cls, secret, config, marker=None): + if not cls.identify(config): + raise uh.exc.InvalidHashError(cls) + elif config: + # preserve the existing str,since it might contain a disabled password hash ("!" + hash) + uh.validate_secret(secret) + return to_native_str(config, param="config") + else: + return cls.hash(secret, marker=marker) + class plaintext(uh.MinimalHandler): """This class stores passwords in plaintext, and follows the :ref:`password-hash-api`. @@ -195,10 +201,7 @@ class plaintext(uh.MinimalHandler): raise uh.exc.ExpectedStringError(hash, "hash") @classmethod - def hash(cls, secret, encoding=None, config=None): - # NOTE: 'config' is ignored, as this hash has no salting / etc - if not (config is None or config is True or cls.identify(config)): - raise uh.exc.InvalidHashError(cls) + def hash(cls, secret, encoding=None): uh.validate_secret(secret) if not encoding: encoding = cls.default_encoding @@ -213,6 +216,19 @@ class plaintext(uh.MinimalHandler): raise uh.exc.InvalidHashError(cls) return str_consteq(cls.hash(secret, encoding), hash) + @uh.deprecated_method(deprecated="1.7", removed="2.0") + @classmethod + def genconfig(cls): + return cls.hash("") + + @uh.deprecated_method(deprecated="1.7", removed="2.0") + @classmethod + def genhash(cls, secret, config, encoding=None): + # NOTE: 'config' is ignored, as this hash has no salting / etc + if not cls.identify(config): + raise uh.exc.InvalidHashError(cls) + return cls.hash(secret, encoding=encoding) + #============================================================================= # eof #============================================================================= |