Skip to content

Commit

Permalink
Rename fips_safe_md5 to md5
Browse files Browse the repository at this point in the history
  • Loading branch information
lhupfeldt committed May 5, 2020
1 parent 193d141 commit 8bbc7b8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from sphinx.locale import _, __
from sphinx.search import js_index
from sphinx.theming import HTMLThemeFactory
from sphinx.util import logging, progress_message, status_iterator, fips_safe_md5
from sphinx.util import logging, progress_message, status_iterator, md5
from sphinx.util.docutils import is_html5_writer_available, new_document
from sphinx.util.fileutil import copy_asset
from sphinx.util.i18n import format_date
Expand Down Expand Up @@ -76,7 +76,7 @@ def get_stable_hash(obj: Any) -> str:
return get_stable_hash(list(obj.items()))
elif isinstance(obj, (list, tuple)):
obj = sorted(get_stable_hash(o) for o in obj)
return fips_safe_md5(str(obj).encode()).hexdigest()
return md5(str(obj).encode()).hexdigest()


class Stylesheet(str):
Expand Down
4 changes: 2 additions & 2 deletions sphinx/ext/inheritance_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class E(B): pass
graphviz, figure_wrapper,
render_dot_html, render_dot_latex, render_dot_texinfo
)
from sphinx.util import fips_safe_md5
from sphinx.util import md5
from sphinx.util.docutils import SphinxDirective
from sphinx.writers.html import HTMLTranslator
from sphinx.writers.latex import LaTeXTranslator
Expand Down Expand Up @@ -387,7 +387,7 @@ def run(self) -> List[Node]:

def get_graph_hash(node: inheritance_diagram) -> str:
encoded = (node['content'] + str(node['parts'])).encode()
return fips_safe_md5(encoded).hexdigest()[-10:]
return md5(encoded).hexdigest()[-10:]


def html_visit_inheritance_diagram(self: HTMLTranslator, node: inheritance_diagram) -> None:
Expand Down
10 changes: 5 additions & 5 deletions sphinx/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import fnmatch
import functools
import hashlib
import os
import posixpath
import re
Expand All @@ -21,7 +22,6 @@
from codecs import BOM_UTF8
from collections import deque
from datetime import datetime
from hashlib import md5
from importlib import import_module
from os import path
from time import mktime, strptime
Expand Down Expand Up @@ -170,7 +170,7 @@ def __setstate__(self, state: Set[str]) -> None:
self._existing = state


def fips_safe_md5(data=b'', **kwargs):
def md5(data=b'', **kwargs):
"""Wrapper around hashlib.md5
Attempt call with 'usedforsecurity=False' if we get a ValueError, which happens when
Expand All @@ -181,9 +181,9 @@ def fips_safe_md5(data=b'', **kwargs):
"""

try:
return md5(data, **kwargs) # type: ignore
return hashlib.md5(data, **kwargs) # type: ignore
except ValueError:
return md5(data, **kwargs, usedforsecurity=False) # type: ignore
return hashlib.md5(data, **kwargs, usedforsecurity=False) # type: ignore


class DownloadFiles(dict):
Expand All @@ -195,7 +195,7 @@ class DownloadFiles(dict):

def add_file(self, docname: str, filename: str) -> str:
if filename not in self:
digest = fips_safe_md5(filename.encode()).hexdigest()
digest = md5(filename.encode()).hexdigest()
dest = '%s/%s' % (digest, os.path.basename(filename))
self[filename] = (set(), dest)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_build_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from sphinx.builders.html import validate_html_extra_path, validate_html_static_path
from sphinx.errors import ConfigError
from sphinx.testing.util import strip_escseq
from sphinx.util import docutils, fips_safe_md5
from sphinx.util import docutils, md5
from sphinx.util.inventory import InventoryFile


Expand Down Expand Up @@ -449,9 +449,9 @@ def test_html_download(app):
@pytest.mark.sphinx('html', testroot='roles-download')
def test_html_download_role(app, status, warning):
app.build()
digest = fips_safe_md5(b'dummy.dat').hexdigest()
digest = md5(b'dummy.dat').hexdigest()
assert (app.outdir / '_downloads' / digest / 'dummy.dat').exists()
digest_another = fips_safe_md5(b'another/dummy.dat').hexdigest()
digest_another = md5(b'another/dummy.dat').hexdigest()
assert (app.outdir / '_downloads' / digest_another / 'dummy.dat').exists()

content = (app.outdir / 'index.html').read_text()
Expand Down

0 comments on commit 8bbc7b8

Please sign in to comment.