diff --git a/oslo_utils/secretutils.py b/oslo_utils/secretutils.py index f6a465c0..9e760d2f 100644 --- a/oslo_utils/secretutils.py +++ b/oslo_utils/secretutils.py @@ -21,6 +21,8 @@ Secret utilities. import hashlib import hmac +import debtcollector.removals + def _constant_time_compare(first, second): """Return True if both string or binary inputs are equal, otherwise False. @@ -46,22 +48,14 @@ try: 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 +@debtcollector.removals.remove(message='Use hashlib.md5 instead', + category=PendingDeprecationWarning) +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 + 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 diff --git a/releasenotes/notes/deprecate-md5-cc365c25c2a51a8c.yaml b/releasenotes/notes/deprecate-md5-cc365c25c2a51a8c.yaml new file mode 100644 index 00000000..40175a96 --- /dev/null +++ b/releasenotes/notes/deprecate-md5-cc365c25c2a51a8c.yaml @@ -0,0 +1,6 @@ +--- +deprecations: + - | + The ``md5`` method from ``oslo_utils.secretutils`` module has been + deprecated because ``hashlib.md5`` can be used instead in all supported + python versions.