Skip to content

Commit 14b4a43

Browse files
committed
feat: Indicate that md5 is used as a CRC
MD5 in storage helpers is used as a CRC function for non-cryptographically secure purposes. Ensure that md5 is initiated with `usedforsecurity=False` to ensure that Python in FIPS mode can fetch MD5 implementation for such non cryptographically secure purpose. This is no effective change on non-FIPS mode Python installations. This improves compatibility with most FIPS mode Python installations.
1 parent b4ce8da commit 14b4a43

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

google/cloud/storage/_helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import datetime
2222
from hashlib import md5
2323
import os
24+
import sys
2425
from urllib.parse import urlsplit
2526
from urllib.parse import urlunsplit
2627
from uuid import uuid4
@@ -536,7 +537,10 @@ def _base64_md5hash(buffer_object):
536537
:rtype: str
537538
:returns: A base64 encoded digest of the MD5 hash.
538539
"""
539-
hash_obj = md5()
540+
if sys.version_info >= (3, 9):
541+
hash_obj = md5(usedforsecurity=False)
542+
else:
543+
hash_obj = md5()
540544
_write_buffer_to_hash(buffer_object, hash_obj)
541545
digest_bytes = hash_obj.digest()
542546
return base64.b64encode(digest_bytes)

0 commit comments

Comments
 (0)