Skip to content

Commit

Permalink
refactor: add 'usedforsecurity=False' arg to hashlib.md5 usage
Browse files Browse the repository at this point in the history
  • Loading branch information
cquick01 committed Sep 15, 2022
1 parent 8ab4c3b commit 650c03f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lark/lark.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None:
options_str = ''.join(k+str(v) for k, v in options.items() if k not in unhashable)
from . import __version__
s = grammar + options_str + __version__ + str(sys.version_info[:2])
cache_md5 = hashlib.md5(s.encode('utf8')).hexdigest()
cache_md5 = hashlib.new("md5", s.encode('utf8'), usedforsecurity=False).hexdigest()

if isinstance(self.options.cache, str):
cache_fn = self.options.cache
Expand Down
4 changes: 2 additions & 2 deletions lark/load_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ def do_import(self, dotted_path: Tuple[str, ...], base_path: Optional[str], alia
except IOError:
continue
else:
h = hashlib.md5(text.encode('utf8')).hexdigest()
h = hashlib.new("md5", text.encode("utf8"), usedforsecurity=False).hexdigest()
if self.used_files.get(joined_path, h) != h:
raise RuntimeError("Grammar file was changed during importing")
self.used_files[joined_path] = h
Expand Down Expand Up @@ -1391,7 +1391,7 @@ def verify_used_files(file_hashes):
if text is None: # We don't know how to load the path. ignore it.
continue

current = hashlib.md5(text.encode()).hexdigest()
current = hashlib.new("md5", text.encode(), usedforsecurity=False).hexdigest()
if old != current:
logger.info("File %r changed, rebuilding Parser" % path)
return False
Expand Down

0 comments on commit 650c03f

Please sign in to comment.