aws / aws-sdk-cpp

AWS SDK for C++
Apache License 2.0
1.96k stars 1.05k forks source link

do not require checksum algorithm when checksum is set #2871

Closed sbiscigl closed 7 months ago

sbiscigl commented 7 months ago

Description of changes:

There is an issue where if you specify a checksum but not the checksum algorithm the functions ChecksumAlgorithmHasBeenSet and GetChecksumAlgorithmName would not return the expected value. This issue especially shows its head when you are using s3express and do something like

const auto client = Aws::MakeUnique<S3Client>("test");
auto request = PutObjectRequest().WithBucket(BUCKET_NAME)
    .WithKey("test-key")
    .WithChecksumSHA256(HashingUtils::Base64Encode(HashingUtils::CalculateSHA256("somebody")));

std::shared_ptr<IOStream> body = Aws::MakeShared<StringStream>("Test",
  "somebody",
  std::ios_base::in | std::ios_base::binary);
request.SetBody(body);
const auto response = client->PutObject(request);

we use the logic in ChecksumAlgorithmHasBeenSet and GetChecksumAlgorithmName to determine if we need to default to crc32 as s3express does not support md5.

This changes to call SetChecksumAlgorithm when setting a checksum so that the implicit requirement of setting the checksum algorithm is no longer required.

Check all that applies:

Check which platforms you have built SDK on to verify the correctness of this PR.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.