Added x-amz-checksum-sha256 header for Object Lock support#1393
Added x-amz-checksum-sha256 header for Object Lock support#1393AlexisPPLIN wants to merge 2 commits intos3tools:masterfrom
Conversation
|
Sorry for the long delay of my reply. |
d9bae67 to
71b8ab3
Compare
|
Hi ! I fixed my import like you advised me to. |
| # Extract digest from sha256 hash | ||
| sha256_hash_digest = sha256_hash.digest() | ||
| # Then convert it to base64 | ||
| sha256_hash_digest_b64 = b64encode(sha256_hash_digest).decode() |
There was a problem hiding this comment.
In this module encodestring (which imported above as an alias of encodebytes when available) is the function used for base64 encoding.
I think you can use:
sha256_hash_digest_b64 = encodestring(sha256_hash_digest).strip().decode()to align with other usecases.
| # Provide the checksum with the request. This is important for buckets that have | ||
| # Object Lock enabled. | ||
|
|
||
| headers['x-amz-checksum-sha256'] = sha256_hash_to_base64(sha256_hash) |
There was a problem hiding this comment.
As someone could use s3cmd as library this line can override the header potentially comes with request argument's headers attribute. I think it's better to check if it currently has values:
if not headers.get("x-amz-checksum-sha256"):
headers['x-amz-checksum-sha256'] = sha256_hash_to_base64(sha256_hash)
This is a follow-up of PR #1353 which is inactive since Dec 5, 2023
As asked I moved the sha256 digest to base64 string into a separate function into
S3/Crypto.pyFixes #1177