summaryrefslogtreecommitdiff
path: root/passlib/utils
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2020-05-02 14:14:25 -0400
committerEli Collins <elic@assurancetechnologies.com>2020-05-02 14:14:25 -0400
commit18aa5a99271908054b8fc65d79c91c8404d486af (patch)
tree9750869367a4290a26857c7500f2ca271deda112 /passlib/utils
parent61f4f3ba5d520dc5b35415be7c9dae49911429db (diff)
downloadpasslib-18aa5a99271908054b8fc65d79c91c8404d486af.tar.gz
reworked lookup_hash() and create_hex_digest() internals to work better
on FIPS systems (issue 116). * lookup_hash(): - moved all hash consturctor error checks / handling into HashInfo object, which simplifies lookup_hash() internals - [minor] added "required" kwd, inverse of the now-deprecated "return_unknown" kwd - [minor] now caches unknown/unsupported HashInfo records. * HashInfo: - now catches ValueErrors thrown by hash constructor, and special-cased detection of "disabled for fips" errors. - stub instances now have constructor that throws UnknownHashError, instead of being None. calling code should detect stub instances via the new "not info.supported" instead of testing for "info.const is None". * create_hex_digest() now defaults to creating handlers w/ mock hash func when it's not present (e.g. due to FIPS). this should let them be imported; and defer the errors until they're actually used. * added _set_mock_fips_mode() and some helps to make lookup_hash() fake a FIPS mode system (per traceback provided in issue comments). used this to make some preliminary UTs for the digest & hasher changes above.
Diffstat (limited to 'passlib/utils')
-rw-r--r--passlib/utils/compat/__init__.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py
index fe3b906..1d6cf4d 100644
--- a/passlib/utils/compat/__init__.py
+++ b/passlib/utils/compat/__init__.py
@@ -288,15 +288,20 @@ def get_unbound_method_function(func):
"""given unbound method, return underlying function"""
return func if PY3 else func.__func__
-def suppress_cause(exc):
+def error_from(exc, # *,
+ cause=None):
"""
backward compat hack to suppress exception cause in python3.3+
one python < 3.3 support is dropped, can replace all uses with "raise exc from None"
"""
- exc.__cause__ = None
+ exc.__cause__ = cause
+ exc.__suppress_context__ = True
return exc
+# legacy alias
+suppress_cause = error_from
+
#=============================================================================
# input/output
#=============================================================================