mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Introduce fips safe sha1, see issue #7611
This commit is contained in:
@@ -12,7 +12,6 @@
|
|||||||
import posixpath
|
import posixpath
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
from hashlib import sha1
|
|
||||||
from os import path
|
from os import path
|
||||||
from subprocess import CalledProcessError, PIPE
|
from subprocess import CalledProcessError, PIPE
|
||||||
from typing import Any, Dict, List, Tuple
|
from typing import Any, Dict, List, Tuple
|
||||||
@@ -25,7 +24,7 @@ import sphinx
|
|||||||
from sphinx.application import Sphinx
|
from sphinx.application import Sphinx
|
||||||
from sphinx.errors import SphinxError
|
from sphinx.errors import SphinxError
|
||||||
from sphinx.locale import _, __
|
from sphinx.locale import _, __
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging, sha1
|
||||||
from sphinx.util.docutils import SphinxDirective, SphinxTranslator
|
from sphinx.util.docutils import SphinxDirective, SphinxTranslator
|
||||||
from sphinx.util.fileutil import copy_asset
|
from sphinx.util.fileutil import copy_asset
|
||||||
from sphinx.util.i18n import search_image_for_language
|
from sphinx.util.i18n import search_image_for_language
|
||||||
|
@@ -14,7 +14,6 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from hashlib import sha1
|
|
||||||
from os import path
|
from os import path
|
||||||
from subprocess import CalledProcessError, PIPE
|
from subprocess import CalledProcessError, PIPE
|
||||||
from typing import Any, Dict, List, Tuple
|
from typing import Any, Dict, List, Tuple
|
||||||
@@ -30,7 +29,7 @@ from sphinx.config import Config
|
|||||||
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
|
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
|
||||||
from sphinx.errors import SphinxError
|
from sphinx.errors import SphinxError
|
||||||
from sphinx.locale import _, __
|
from sphinx.locale import _, __
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging, sha1
|
||||||
from sphinx.util.math import get_node_equation_number, wrap_displaymath
|
from sphinx.util.math import get_node_equation_number, wrap_displaymath
|
||||||
from sphinx.util.osutil import ensuredir
|
from sphinx.util.osutil import ensuredir
|
||||||
from sphinx.util.png import read_png_depth, write_png_depth
|
from sphinx.util.png import read_png_depth, write_png_depth
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from hashlib import sha1
|
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from typing import Any, Dict, List, Tuple
|
from typing import Any, Dict, List, Tuple
|
||||||
|
|
||||||
@@ -19,7 +18,7 @@ from docutils import nodes
|
|||||||
from sphinx.application import Sphinx
|
from sphinx.application import Sphinx
|
||||||
from sphinx.locale import __
|
from sphinx.locale import __
|
||||||
from sphinx.transforms import SphinxTransform
|
from sphinx.transforms import SphinxTransform
|
||||||
from sphinx.util import epoch_to_rfc1123, rfc1123_to_epoch
|
from sphinx.util import epoch_to_rfc1123, rfc1123_to_epoch, sha1
|
||||||
from sphinx.util import logging, requests
|
from sphinx.util import logging, requests
|
||||||
from sphinx.util.images import guess_mimetype, get_image_extension, parse_data_uri
|
from sphinx.util.images import guess_mimetype, get_image_extension, parse_data_uri
|
||||||
from sphinx.util.osutil import ensuredir, movefile
|
from sphinx.util.osutil import ensuredir, movefile
|
||||||
|
@@ -186,6 +186,20 @@ def md5(data=b'', **kwargs):
|
|||||||
return hashlib.md5(data, **kwargs, usedforsecurity=False) # type: ignore
|
return hashlib.md5(data, **kwargs, usedforsecurity=False) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
return hashlib.sha1(data, **kwargs) # type: ignore
|
||||||
|
except ValueError:
|
||||||
|
return hashlib.sha1(data, **kwargs, usedforsecurity=False) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
class DownloadFiles(dict):
|
class DownloadFiles(dict):
|
||||||
"""A special dictionary for download files.
|
"""A special dictionary for download files.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user