From 13a87d807089b3eebb8127136fac58b6cd65a68d Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Fri, 6 Jan 2023 19:00:22 +0000 Subject: [PATCH] Call ``hashlib`` functions with ``usedforsecurity=False`` --- sphinx/util/__init__.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index f38e74d8f..1f0025782 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -6,6 +6,7 @@ import hashlib import os import posixpath import re +import sys import warnings from importlib import import_module from os import path @@ -133,31 +134,23 @@ class FilenameUniqDict(dict): def md5(data=b'', **kwargs): """Wrapper around hashlib.md5 - Attempt call with 'usedforsecurity=False' if we get a ValueError, which happens when - OpenSSL FIPS mode is enabled: - ValueError: error:060800A3:digital envelope routines:EVP_DigestInit_ex:disabled for fips - - See: https://github.com/sphinx-doc/sphinx/issues/7611 + Attempt call with 'usedforsecurity=False' if supported. """ - try: - return hashlib.md5(data, **kwargs) - except ValueError: - return hashlib.md5(data, **kwargs, usedforsecurity=False) # type: ignore + if sys.version_info[:2] > (3, 8): + return hashlib.md5(data, usedforsecurity=False) + return hashlib.md5(data, **kwargs) def sha1(data=b'', **kwargs): """Wrapper around hashlib.sha1 - Attempt call with 'usedforsecurity=False' if we get a ValueError - - See: https://github.com/sphinx-doc/sphinx/issues/7611 + Attempt call with 'usedforsecurity=False' if supported. """ - try: - return hashlib.sha1(data, **kwargs) - except ValueError: - return hashlib.sha1(data, **kwargs, usedforsecurity=False) # type: ignore + if sys.version_info[:2] > (3, 8): + return hashlib.sha1(data, usedforsecurity=False) + return hashlib.sha1(data, **kwargs) class DownloadFiles(dict):