66#include < aws/core/platform/FileSystem.h>
77#include < aws/core/utils/HashingUtils.h>
88#include < aws/core/utils/logging/LogMacros.h>
9+ #include < aws/core/utils/crypto/Hash.h>
10+ #include < aws/core/utils/crypto/CRC32.h>
911#include < aws/core/utils/memory/AWSMemory.h>
1012#include < aws/core/utils/memory/stl/AWSStreamFwd.h>
1113#include < aws/core/utils/memory/stl/AWSStringStream.h>
@@ -399,6 +401,15 @@ namespace Aws
399401 bool isRetry = !handle->GetMultiPartId ().empty ();
400402 uint64_t sentBytes = 0 ;
401403
404+ std::shared_ptr<Aws::Utils::Crypto::Hash> fullObjectHashCalculator;
405+ if (handle->GetChecksum ().empty () && !isRetry) {
406+ if (m_transferConfig.checksumAlgorithm == S3::Model::ChecksumAlgorithm::CRC32C) {
407+ fullObjectHashCalculator = Aws::MakeShared<Aws::Utils::Crypto::CRC32C>(" TransferManager" );
408+ } else if (m_transferConfig.checksumAlgorithm == S3::Model::ChecksumAlgorithm::CRC32) {
409+ fullObjectHashCalculator = Aws::MakeShared<Aws::Utils::Crypto::CRC32>(" TransferManager" );
410+ }
411+ }
412+
402413 if (!isRetry) {
403414 Aws::S3::Model::CreateMultipartUploadRequest createMultipartRequest = m_transferConfig.createMultipartUploadTemplate ;
404415 createMultipartRequest.SetChecksumAlgorithm (m_transferConfig.checksumAlgorithm );
@@ -466,6 +477,10 @@ namespace Aws
466477 streamToPut->seekg ((partsIter->first - 1 ) * m_transferConfig.bufferSize );
467478 streamToPut->read (reinterpret_cast <char *>(buffer), lengthToWrite);
468479
480+ if (fullObjectHashCalculator) {
481+ fullObjectHashCalculator->Update (buffer, static_cast <size_t >(lengthToWrite));
482+ }
483+
469484 auto streamBuf = Aws::New<Aws::Utils::Stream::PreallocatedStreamBuf>(CLASS_TAG, buffer, static_cast <size_t >(lengthToWrite));
470485 auto preallocatedStreamReader = Aws::MakeShared<Aws::IOStream>(CLASS_TAG, streamBuf);
471486
@@ -525,6 +540,13 @@ namespace Aws
525540 handle->UpdateStatus (DetermineIfFailedOrCanceled (*handle));
526541 TriggerTransferStatusUpdatedCallback (handle);
527542 }
543+ else if (fullObjectHashCalculator && handle->GetChecksum ().empty ()) {
544+ // Finalize checksum calculation and set on handle
545+ auto hashResult = fullObjectHashCalculator->GetHash ();
546+ if (hashResult.IsSuccess ()) {
547+ handle->SetChecksum (Aws::Utils::HashingUtils::Base64Encode (hashResult.GetResult ()));
548+ }
549+ }
528550 }
529551
530552 void TransferManager::DoSinglePartUpload (const std::shared_ptr<TransferHandle>& handle)
@@ -1508,4 +1530,4 @@ namespace Aws
15081530 }
15091531 }
15101532 }
1511- }
1533+ }
0 commit comments