Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark use of hashlib.md5() as not for security #415

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
History
=======

* Work on FIPS Python 3.9+, by declaring use of ``hashlib.md5()`` as not used for security.

Thanks to dantebben for the report in `Issue #414 <https://github.com/pytest-dev/pytest-randomly/issues/414>`__.

3.10.2 (2021-11-10)
-------------------

Expand Down
4 changes: 3 additions & 1 deletion src/pytest_randomly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from _pytest.nodes import Item
from pytest import Collector, fixture, hookimpl

from pytest_randomly.compat import md5

if sys.version_info < (3, 10):
from importlib_metadata import entry_points
else:
Expand Down Expand Up @@ -274,7 +276,7 @@ def reduce_list_of_lists(lists: List[List[T]]) -> List[T]:


def _md5(string: str) -> bytes:
hasher = hashlib.md5()
hasher = md5()
hasher.update(string.encode())
return hasher.digest()

Expand Down
8 changes: 8 additions & 0 deletions src/pytest_randomly/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import hashlib
import sys
from functools import partial

if sys.version_info >= (3, 9):
md5 = partial(hashlib.md5, usedforsecurity=False)
else:
md5 = hashlib.md5