Skip to content

Commit eddcfdf

Browse files
committed
Completely remove deprecated legacy checksum options
1 parent 2cdd5f7 commit eddcfdf

20 files changed

Lines changed: 114 additions & 325 deletions

google/cloud/storage/client_object_test.cc

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -234,119 +234,6 @@ TEST_F(ObjectTest, ReadObject) {
234234
EXPECT_EQ(actual.gcount(), 1024);
235235
}
236236

237-
TEST_F(ObjectTest, ReadObjectChecksumPrecedence) {
238-
EXPECT_CALL(*mock_, ReadObject)
239-
.WillOnce([](internal::ReadObjectRangeRequest const& r) {
240-
EXPECT_TRUE(r.HasOption<DisableMD5Hash>());
241-
EXPECT_FALSE(r.GetOption<DisableMD5Hash>().value());
242-
243-
auto settings =
244-
internal::GetDownloadChecksumSettings(r, CurrentOptions());
245-
// Verify MD5 is enabled (disable_md5 = false) and CRC32C is disabled
246-
// (disable_crc32c = true)
247-
EXPECT_FALSE(settings.md5);
248-
EXPECT_TRUE(settings.crc32c);
249-
250-
auto read_source = std::make_unique<testing::MockObjectReadSource>();
251-
EXPECT_CALL(*read_source, IsOpen()).WillRepeatedly(Return(true));
252-
EXPECT_CALL(*read_source, Read)
253-
.WillOnce(Return(internal::ReadSourceResult{1024, {}}));
254-
EXPECT_CALL(*read_source, Close).Times(1);
255-
return StatusOr<std::unique_ptr<internal::ObjectReadSource>>(
256-
std::move(read_source));
257-
});
258-
auto client = ClientForMock();
259-
auto actual = client.ReadObject(
260-
"test-bucket-name", "test-object-name", DisableMD5Hash(false),
261-
Options{}.set<DownloadChecksumValidationOption>(
262-
ChecksumAlgorithm::kNone));
263-
ASSERT_STATUS_OK(actual.status());
264-
std::vector<char> v(1024);
265-
actual.read(v.data(), v.size());
266-
EXPECT_EQ(actual.gcount(), 1024);
267-
}
268-
269-
TEST_F(ObjectTest, ReadObjectChecksumPrecedenceDisableMD5) {
270-
EXPECT_CALL(*mock_, ReadObject)
271-
.WillOnce([](internal::ReadObjectRangeRequest const& r) {
272-
EXPECT_TRUE(r.HasOption<DisableMD5Hash>());
273-
EXPECT_TRUE(r.GetOption<DisableMD5Hash>().value());
274-
275-
auto settings =
276-
internal::GetDownloadChecksumSettings(r, CurrentOptions());
277-
// DisableMD5Hash(true) should override ChecksumAlgorithm::kMD5
278-
EXPECT_TRUE(settings.md5);
279-
EXPECT_TRUE(settings.crc32c); // kMD5 disables crc32c
280-
281-
auto read_source = std::make_unique<testing::MockObjectReadSource>();
282-
EXPECT_CALL(*read_source, IsOpen()).WillRepeatedly(Return(true));
283-
EXPECT_CALL(*read_source, Read)
284-
.WillOnce(Return(internal::ReadSourceResult{1024, {}}));
285-
EXPECT_CALL(*read_source, Close).Times(1);
286-
return StatusOr<std::unique_ptr<internal::ObjectReadSource>>(
287-
std::move(read_source));
288-
});
289-
auto client = ClientForMock();
290-
auto actual = client.ReadObject(
291-
"test-bucket-name", "test-object-name", DisableMD5Hash(true),
292-
Options{}.set<DownloadChecksumValidationOption>(ChecksumAlgorithm::kMD5));
293-
ASSERT_STATUS_OK(actual.status());
294-
std::vector<char> v(1024);
295-
actual.read(v.data(), v.size());
296-
EXPECT_EQ(actual.gcount(), 1024);
297-
}
298-
299-
TEST_F(ObjectTest, InsertObjectChecksumPrecedence) {
300-
EXPECT_CALL(*mock_, InsertObjectMedia)
301-
.WillOnce([](internal::InsertObjectMediaRequest const& r) {
302-
EXPECT_TRUE(r.HasOption<DisableCrc32cChecksum>());
303-
EXPECT_TRUE(r.GetOption<DisableCrc32cChecksum>().value());
304-
305-
auto settings =
306-
internal::GetUploadChecksumSettings(r, CurrentOptions());
307-
// Verify CRC32C is disabled (disable_crc32c = true) and MD5 remains
308-
// enabled (disable_md5 = false)
309-
EXPECT_TRUE(settings.crc32c);
310-
EXPECT_FALSE(settings.md5);
311-
312-
return make_status_or(
313-
storage::internal::ObjectMetadataParser::FromString(
314-
R"({"name": "test-object-name"})")
315-
.value());
316-
});
317-
auto client = ClientForMock();
318-
auto actual =
319-
client.InsertObject("test-bucket-name", "test-object-name", "payload",
320-
DisableCrc32cChecksum(true),
321-
Options{}.set<UploadChecksumValidationOption>(
322-
ChecksumAlgorithm::kCrc32cAndMD5));
323-
ASSERT_STATUS_OK(actual);
324-
}
325-
326-
TEST_F(ObjectTest, InsertObjectChecksumPrecedenceEnableCrc32c) {
327-
EXPECT_CALL(*mock_, InsertObjectMedia)
328-
.WillOnce([](internal::InsertObjectMediaRequest const& r) {
329-
EXPECT_TRUE(r.HasOption<DisableCrc32cChecksum>());
330-
EXPECT_FALSE(r.GetOption<DisableCrc32cChecksum>().value());
331-
332-
auto settings =
333-
internal::GetUploadChecksumSettings(r, CurrentOptions());
334-
// DisableCrc32cChecksum(false) should override ChecksumAlgorithm::kNone
335-
EXPECT_FALSE(settings.crc32c);
336-
EXPECT_TRUE(settings.md5); // kNone disables md5
337-
338-
return make_status_or(
339-
storage::internal::ObjectMetadataParser::FromString(
340-
R"({"name": "test-object-name"})")
341-
.value());
342-
});
343-
auto client = ClientForMock();
344-
auto actual = client.InsertObject(
345-
"test-bucket-name", "test-object-name", "payload",
346-
DisableCrc32cChecksum(false),
347-
Options{}.set<UploadChecksumValidationOption>(ChecksumAlgorithm::kNone));
348-
ASSERT_STATUS_OK(actual);
349-
}
350237

351238
TEST_F(ObjectTest, WriteObject) {
352239
EXPECT_CALL(*mock_, CreateResumableUpload)

google/cloud/storage/hashing_options.h

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -62,40 +62,7 @@ inline std::string ComputeMD5Hash(char const* payload) {
6262
}
6363

6464
/**
65-
* Disable or enable MD5 Hashing computations.
66-
*
67-
* By default MD5 hashes are disabled. To enable them use the
68-
* `EnableMD5Hash()` helper function.
69-
*
70-
* @warning MD5 hashes are disabled by default, as they are computationally
71-
* expensive, and CRC32C checksums provide enough data integrity protection
72-
* for most applications. Disabling CRC32C checksums while MD5 hashes remain
73-
* disabled exposes your application to data corruption. We recommend that all
74-
* uploads to GCS and downloads from GCS use CRC32C checksums.
75-
*
76-
* @deprecated Use `UploadChecksumValidationOption` and
77-
* `DownloadChecksumValidationOption` instead.
78-
*/
79-
struct [[deprecated(
80-
"Use UploadChecksumValidationOption and DownloadChecksumValidationOption "
81-
"instead")]] DisableMD5Hash
82-
: public internal::ComplexOption<DisableMD5Hash, bool> {
83-
using ComplexOption<DisableMD5Hash, bool>::ComplexOption;
84-
// GCC <= 7.0 does not use the inherited default constructor, redeclare it
85-
// explicitly
86-
DisableMD5Hash() = default;
87-
static char const* name() { return "disable-md5-hash"; }
88-
};
89-
90-
/**
91-
* Enable MD5 hashes in upload and download operations.
92-
*
93-
* Use this function where the option `DisableMD5Hash` is expected to enable MD5
94-
* hashes.
95-
*/
96-
inline DisableMD5Hash EnableMD5Hash() { return DisableMD5Hash(false); }
9765
98-
/**
9966
* Provide a pre-computed CRC32C checksum value.
10067
*
10168
* The application may be able to obtain a CRC32C checksum in some out-of-band
@@ -130,32 +97,6 @@ inline std::string ComputeCrc32cChecksum(char const* payload) {
13097
: absl::string_view{payload});
13198
}
13299

133-
/**
134-
* Disable CRC32C checksum computations.
135-
*
136-
* By default the GCS client library computes CRC32C checksums in all upload and
137-
* download operations. The application can use this option to disable the
138-
* checksum computation.
139-
*
140-
* @warning MD5 hashes are disabled by default, as they are computationally
141-
* expensive, and CRC32C checksums provide enough data integrity protection
142-
* for most applications. Disabling CRC32C checksums while MD5 hashes remain
143-
* disabled exposes your application to data corruption. We recommend that all
144-
* uploads to GCS and downloads from GCS use CRC32C checksums.
145-
*
146-
* @deprecated Use `UploadChecksumValidationOption` and
147-
* `DownloadChecksumValidationOption` instead.
148-
*/
149-
struct [[deprecated(
150-
"Use UploadChecksumValidationOption and DownloadChecksumValidationOption "
151-
"instead")]] DisableCrc32cChecksum
152-
: public internal::ComplexOption<DisableCrc32cChecksum, bool> {
153-
using ComplexOption<DisableCrc32cChecksum, bool>::ComplexOption;
154-
// GCC <= 7.0 does not use the inherited default constructor, redeclare it
155-
// explicitly
156-
DisableCrc32cChecksum() = default;
157-
static char const* name() { return "disable-crc32c-checksum"; }
158-
};
159100

160101
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
161102
} // namespace storage

google/cloud/storage/internal/checksum_helpers.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct HashDisabled {
3232
};
3333

3434
template <typename Request>
35-
HashDisabled GetDownloadChecksumSettings(Request const& request,
35+
HashDisabled GetDownloadChecksumSettings(Request const&,
3636
Options const& options) {
3737
bool disable_md5 = true;
3838
bool disable_crc32c = false;
@@ -44,19 +44,12 @@ HashDisabled GetDownloadChecksumSettings(Request const& request,
4444
algo != ChecksumAlgorithm::kCrc32cAndMD5);
4545
}
4646

47-
auto const md5 = request.template GetOption<DisableMD5Hash>();
48-
if (md5.has_value()) {
49-
disable_md5 = md5.value();
50-
}
51-
auto const crc32c = request.template GetOption<DisableCrc32cChecksum>();
52-
if (crc32c.has_value()) {
53-
disable_crc32c = crc32c.value();
54-
}
47+
5548
return {disable_md5, disable_crc32c};
5649
}
5750

5851
template <typename Request>
59-
HashDisabled GetUploadChecksumSettings(Request const& request,
52+
HashDisabled GetUploadChecksumSettings(Request const&,
6053
Options const& options) {
6154
bool disable_md5 = true;
6255
bool disable_crc32c = false;
@@ -68,14 +61,7 @@ HashDisabled GetUploadChecksumSettings(Request const& request,
6861
algo != ChecksumAlgorithm::kCrc32cAndMD5);
6962
}
7063

71-
auto const md5 = request.template GetOption<DisableMD5Hash>();
72-
if (md5.has_value()) {
73-
disable_md5 = md5.value();
74-
}
75-
auto const crc32c = request.template GetOption<DisableCrc32cChecksum>();
76-
if (crc32c.has_value()) {
77-
disable_crc32c = crc32c.value();
78-
}
64+
7965
return {disable_md5, disable_crc32c};
8066
}
8167

google/cloud/storage/internal/connection_impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ This is often a problem because:
814814
preserve data integrity.
815815
816816
Consider using UploadLimit option or Client::WriteObject(). You may also need to disable data
817-
integrity checks using the DisableMD5Hash() and DisableCrc32cChecksum() options.
817+
integrity checks using the UploadChecksumValidationOption() option.
818818
)""";
819819
} else {
820820
std::error_code size_err;

google/cloud/storage/internal/grpc/stub.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,9 @@ StatusOr<storage::ObjectMetadata> GrpcStub::InsertObjectMedia(
350350

351351
auto const settings =
352352
storage::internal::GetUploadChecksumSettings(request, options);
353-
auto disable_md5 = storage::DisableMD5Hash(settings.md5);
354-
auto disable_crc32c = storage::DisableCrc32cChecksum(settings.crc32c);
355353
auto hash_function = storage::internal::CreateHashFunction(
356-
request.GetOption<storage::Crc32cChecksumValue>(), disable_crc32c,
357-
request.GetOption<storage::MD5HashValue>(), disable_md5);
354+
request.GetOption<storage::Crc32cChecksumValue>(), settings.crc32c,
355+
request.GetOption<storage::MD5HashValue>(), settings.md5);
358356

359357
auto splitter = SplitObjectWriteData<ContentType>(request.payload());
360358
std::int64_t offset = 0;

google/cloud/storage/internal/hash_function.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2929
namespace internal {
3030

3131
std::unique_ptr<HashFunction> CreateHashFunction(
32-
Crc32cChecksumValue const& crc32c_value,
33-
DisableCrc32cChecksum const& crc32c_disabled, MD5HashValue const& md5_value,
34-
DisableMD5Hash const& md5_disabled) {
32+
Crc32cChecksumValue const& crc32c_value, bool disable_crc32c,
33+
MD5HashValue const& md5_value, bool disable_md5) {
3534
auto crc32c = std::unique_ptr<HashFunction>();
3635
auto crc32c_v = crc32c_value.value_or("");
3736
if (!crc32c_v.empty()) {
3837
crc32c = std::make_unique<PrecomputedHashFunction>(
3938
HashValues{/*.crc32c=*/std::move(crc32c_v), /*md5=*/{}});
40-
} else if (!crc32c_disabled.value_or(false)) {
39+
} else if (!disable_crc32c) {
4140
crc32c = std::make_unique<Crc32cHashFunction>();
4241
}
4342

@@ -46,7 +45,7 @@ std::unique_ptr<HashFunction> CreateHashFunction(
4645
if (!md5_v.empty()) {
4746
md5 = std::make_unique<PrecomputedHashFunction>(
4847
HashValues{/*.crc32c=*/{}, /*.md5=*/std::move(md5_v)});
49-
} else if (!md5_disabled.value_or(false)) {
48+
} else if (!disable_md5) {
5049
md5 = MD5HashFunction::Create();
5150
}
5251

@@ -88,11 +87,9 @@ std::unique_ptr<HashFunction> CreateHashFunction(
8887

8988
auto const settings = GetUploadChecksumSettings(
9089
request, google::cloud::internal::CurrentOptions());
91-
auto disable_md5 = DisableMD5Hash(settings.md5);
92-
auto disable_crc32c = DisableCrc32cChecksum(settings.crc32c);
9390
return CreateHashFunction(request.GetOption<Crc32cChecksumValue>(),
94-
disable_crc32c, request.GetOption<MD5HashValue>(),
95-
disable_md5);
91+
settings.crc32c, request.GetOption<MD5HashValue>(),
92+
settings.md5);
9693
}
9794

9895
} // namespace internal

google/cloud/storage/internal/hash_function.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ class HashFunction {
8888

8989
/// Create a hash function configured by several options.
9090
std::unique_ptr<HashFunction> CreateHashFunction(
91-
Crc32cChecksumValue const& crc32c_value,
92-
DisableCrc32cChecksum const& crc32c_disabled, MD5HashValue const& md5_value,
93-
DisableMD5Hash const& md5_disabled);
91+
Crc32cChecksumValue const& crc32c_value, bool disable_crc32c,
92+
MD5HashValue const& md5_value, bool disable_md5);
9493

9594
/// Create a no-op hash function
9695
std::unique_ptr<HashFunction> CreateNullHashFunction();

google/cloud/storage/internal/hash_function_impl_test.cc

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -378,22 +378,19 @@ TEST(HashFunctionImplTest, CreateHashFunctionRead) {
378378
struct Test {
379379
std::string crc32c_expected;
380380
std::string md5_expected;
381-
DisableCrc32cChecksum crc32_disabled;
382-
DisableMD5Hash md5_disabled;
381+
ChecksumAlgorithm validation_algo;
383382
} cases[]{
384-
{"", "", DisableCrc32cChecksum(true), DisableMD5Hash(true)},
385-
{"", kQuickFoxMD5Hash, DisableCrc32cChecksum(true),
386-
DisableMD5Hash(false)},
387-
{kQuickFoxCrc32cChecksum, "", DisableCrc32cChecksum(false),
388-
DisableMD5Hash(true)},
389-
{kQuickFoxCrc32cChecksum, kQuickFoxMD5Hash, DisableCrc32cChecksum(false),
390-
DisableMD5Hash(false)},
383+
{"", "", ChecksumAlgorithm::kNone},
384+
{"", kQuickFoxMD5Hash, ChecksumAlgorithm::kMD5},
385+
{kQuickFoxCrc32cChecksum, "", ChecksumAlgorithm::kCrc32c},
386+
{kQuickFoxCrc32cChecksum, kQuickFoxMD5Hash, ChecksumAlgorithm::kCrc32cAndMD5},
391387
};
392388

393389
for (auto const& test : cases) {
390+
google::cloud::internal::OptionsSpan span(
391+
Options{}.set<DownloadChecksumValidationOption>(test.validation_algo));
394392
auto function = CreateHashFunction(
395-
ReadObjectRangeRequest("test-bucket", "test-object")
396-
.set_multiple_options(test.crc32_disabled, test.md5_disabled));
393+
ReadObjectRangeRequest("test-bucket", "test-object"));
397394
function->Update(kQuickFox);
398395
auto const actual = std::move(*function).Finish();
399396
EXPECT_EQ(test.crc32c_expected, actual.crc32c);
@@ -404,20 +401,21 @@ TEST(HashFunctionImplTest, CreateHashFunctionRead) {
404401
struct UploadTest {
405402
std::string crc32c_expected;
406403
std::string md5_expected;
407-
DisableCrc32cChecksum crc32_disabled;
404+
bool disable_crc32c;
408405
Crc32cChecksumValue crc32_value;
409-
DisableMD5Hash md5_disabled;
406+
bool disable_md5;
410407
MD5HashValue md5_value;
411408
};
412409

413410
TEST(HashFunctionImplTest, CreateHashFunctionUpload) {
414411
auto const upload_cases = testing::UploadHashCases();
415412

416413
for (auto const& test : upload_cases) {
414+
google::cloud::internal::OptionsSpan span(
415+
Options{}.set<UploadChecksumValidationOption>(test.validation_algo));
417416
auto function = CreateHashFunction(
418417
ResumableUploadRequest("test-bucket", "test-object")
419-
.set_multiple_options(test.crc32_disabled, test.crc32_value,
420-
test.md5_disabled, test.md5_value));
418+
.set_multiple_options(test.crc32_value, test.md5_value));
421419
function->Update(kQuickFox);
422420
auto const actual = std::move(*function).Finish();
423421
EXPECT_EQ(test.crc32c_expected, actual.crc32c);
@@ -428,9 +426,7 @@ TEST(HashFunctionImplTest, CreateHashFunctionUpload) {
428426
TEST(HashFunctionImplTest, CreateHashFunctionUploadResumedSession) {
429427
auto function = CreateHashFunction(
430428
ResumableUploadRequest("test-bucket", "test-object")
431-
.set_multiple_options(UseResumableUploadSession("test-session-id"),
432-
DisableCrc32cChecksum(false),
433-
DisableMD5Hash(false)));
429+
.set_multiple_options(UseResumableUploadSession("test-session-id")));
434430
function->Update(kQuickFox);
435431
auto const actual = std::move(*function).Finish();
436432
EXPECT_THAT(actual.crc32c, IsEmpty());
@@ -441,8 +437,9 @@ TEST(HashFunctionImplTest, CreateHashFunctionInsertObjectMedia) {
441437
auto const upload_cases = testing::UploadHashCases();
442438

443439
for (auto const& test : upload_cases) {
444-
auto function = CreateHashFunction(test.crc32_value, test.crc32_disabled,
445-
test.md5_value, test.md5_disabled);
440+
bool disable_crc32c = (test.validation_algo == ChecksumAlgorithm::kNone || test.validation_algo == ChecksumAlgorithm::kMD5);
441+
bool disable_md5 = (test.validation_algo == ChecksumAlgorithm::kNone || test.validation_algo == ChecksumAlgorithm::kCrc32c);
442+
auto function = CreateHashFunction(test.crc32_value, disable_crc32c, test.md5_value, disable_md5);
446443
ASSERT_STATUS_OK(function->Update(/*offset=*/0, kQuickFox));
447444
auto const actual = function->Finish();
448445
EXPECT_EQ(test.crc32c_expected, actual.crc32c);

0 commit comments

Comments
 (0)