Deprecate redundant md5 method

hashlib.md5 always supports usedforsecurity argument in Python 3.9 and
later.

Change-Id: I16502f9ee884ab81c786d46f336a71b8a3c4fb1a
This commit is contained in:
Takashi Kajinami 2024-09-30 17:27:12 +09:00
parent fa2ecb269a
commit f7f21f8028
2 changed files with 17 additions and 17 deletions

View File

@ -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

View File

@ -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.