summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Turner <9087854+aa-turner@users.noreply.github.com>2023-01-06 19:00:22 +0000
committerAdam Turner <9087854+aa-turner@users.noreply.github.com>2023-01-06 19:00:22 +0000
commit13a87d807089b3eebb8127136fac58b6cd65a68d (patch)
treea3779f7fa349dd0dad1328c3083d2c4a0891629a
parentf0dbe8180d4cea463defef559a486597e4fa6789 (diff)
downloadsphinx-git-13a87d807089b3eebb8127136fac58b6cd65a68d.tar.gz
Call ``hashlib`` functions with ``usedforsecurity=False``
-rw-r--r--sphinx/util/__init__.py25
1 files 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):