Skip to content

Commit

Permalink
set usedforsecurity to False when calling hashlib.md5 with Python >= 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Jun 5, 2024
1 parent 4223ede commit 8e845a8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,23 @@
CHECKSUM_TYPE_SHA256 = 'sha256'
DEFAULT_CHECKSUM = CHECKSUM_TYPE_SHA256


def _hashlib_md5():
"""
Wrapper function for hashlib.md5,
to set usedforsecurity to False when supported (Python >= 3.9)
"""
kwargs = {}
if sys.version_info[0] >= 3 and sys.version_info[1] >= 9:
kwargs = {'usedforsecurity': False}
return hashlib.md5(**kwargs)


# map of checksum types to checksum functions
CHECKSUM_FUNCTIONS = {
'adler32': lambda p: calc_block_checksum(p, ZlibChecksum(zlib.adler32)),
'crc32': lambda p: calc_block_checksum(p, ZlibChecksum(zlib.crc32)),
CHECKSUM_TYPE_MD5: lambda p: calc_block_checksum(p, hashlib.md5()),
CHECKSUM_TYPE_MD5: lambda p: calc_block_checksum(p, _hashlib_md5()),
'sha1': lambda p: calc_block_checksum(p, hashlib.sha1()),
CHECKSUM_TYPE_SHA256: lambda p: calc_block_checksum(p, hashlib.sha256()),
'sha512': lambda p: calc_block_checksum(p, hashlib.sha512()),
Expand Down

0 comments on commit 8e845a8

Please sign in to comment.