diff options
Diffstat (limited to 'oslo_utils/secretutils.py')
-rw-r--r-- | oslo_utils/secretutils.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/oslo_utils/secretutils.py b/oslo_utils/secretutils.py index ad350d2..f6a465c 100644 --- a/oslo_utils/secretutils.py +++ b/oslo_utils/secretutils.py @@ -18,6 +18,7 @@ Secret utilities. .. versionadded:: 3.5 """ +import hashlib import hmac @@ -44,3 +45,23 @@ try: constant_time_compare = hmac.compare_digest except AttributeError: constant_time_compare = _constant_time_compare + +try: + _ = hashlib.md5(usedforsecurity=False) # nosec + + def md5(string=b'', usedforsecurity=True): + """Return an md5 hashlib object using usedforsecurity parameter + + For python distributions that support the usedforsecurity keyword + parameter, this passes the parameter through as expected. + See https://bugs.python.org/issue9216 + """ + return hashlib.md5(string, usedforsecurity=usedforsecurity) # nosec +except TypeError: + def md5(string=b'', usedforsecurity=True): + """Return an md5 hashlib object without usedforsecurity parameter + + For python distributions that do not yet support this keyword + parameter, we drop the parameter + """ + return hashlib.md5(string) # nosec |