From bbf2c95503983162005542256afbd76dc8f112ff Mon Sep 17 00:00:00 2001 From: Thomas Holenstein Date: Fri, 15 Nov 2024 08:19:08 -0800 Subject: [PATCH] Migrate from the constructor taking an optional which computes the CRC to WithComputedCrc. Since the CRC will become optional, the other constructor will create an object without CRC. PiperOrigin-RevId: 696894313 Change-Id: Iadd2910b046a4b179ec6e519d11d35c5c23e57b7 --- ..._parser_secret_data_with_crc_field_test.cc | 32 +++++++++---------- tink/internal/proto_parser_test.cc | 12 ++++--- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/tink/internal/proto_parser_secret_data_with_crc_field_test.cc b/tink/internal/proto_parser_secret_data_with_crc_field_test.cc index e06961b1..1dba8b7d 100644 --- a/tink/internal/proto_parser_secret_data_with_crc_field_test.cc +++ b/tink/internal/proto_parser_secret_data_with_crc_field_test.cc @@ -52,7 +52,7 @@ struct ParsedStruct { TEST(SecretDataWithCrcBytesField, ClearMemberWorks) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; - s.secret_with_crc = SecretDataWithCrc("hello"); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc("hello"); field.ClearMember(s); EXPECT_THAT(s.secret_with_crc.UncheckedData(), Eq("")); @@ -62,7 +62,7 @@ TEST(SecretDataWithCrcBytesField, ClearMemberWorks) { TEST(SecretDataWithCrcBytesField, ConsumeIntoMemberSuccessCases) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; - s.secret_with_crc = SecretDataWithCrc("before"); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc("before"); std::string bytes = absl::StrCat(/* 10 bytes */ HexDecodeOrDie("0a"), "1234567890XYZ"); @@ -82,7 +82,7 @@ TEST(SecretDataWithCrcBytesField, ConsumeIntoMemberSuccessCases) { TEST(SecretDataWithCrcBytesField, ConsumeIntoMemberRequiresStateWithCrc) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; - s.secret_with_crc = SecretDataWithCrc("before"); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc("before"); std::string bytes = absl::StrCat(/* 10 bytes */ HexDecodeOrDie("0a"), "1234567890XYZ"); @@ -94,7 +94,7 @@ TEST(SecretDataWithCrcBytesField, ConsumeIntoMemberRequiresStateWithCrc) { TEST(SecretDataWithCrcBytesField, ConsumeIntoMemberVarintSaysTooLong) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; - s.secret_with_crc = SecretDataWithCrc("before"); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc("before"); std::string bytes = absl::StrCat(/* 10 bytes */ HexDecodeOrDie("0b"), "1234567890"); @@ -107,7 +107,7 @@ TEST(SecretDataWithCrcBytesField, ConsumeIntoMemberVarintSaysTooLong) { TEST(SecretDataWithCrcBytesField, ConsumeIntoMemberEmptyString) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; - s.secret_with_crc = SecretDataWithCrc("before"); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc("before"); std::string bytes = absl::StrCat(/* 0 bytes */ HexDecodeOrDie("00"), "abcde"); absl::crc32c_t crc_to_maintain = absl::crc32c_t{}; @@ -124,7 +124,7 @@ TEST(SecretDataWithCrcBytesField, ConsumeIntoMemberEmptyString) { TEST(SecretDataWithCrcBytesField, EmptyWithoutVarint) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; - s.secret_with_crc = SecretDataWithCrc("before"); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc("before"); std::string bytes = ""; absl::crc32c_t crc_to_maintain = absl::crc32c_t{}; @@ -136,7 +136,7 @@ TEST(SecretDataWithCrcBytesField, EmptyWithoutVarint) { TEST(SecretDataWithCrcBytesField, InvalidVarint) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; - s.secret_with_crc = SecretDataWithCrc("before"); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc("before"); std::string bytes = absl::StrCat(HexDecodeOrDie("808080808000"), "abcde"); absl::crc32c_t crc_to_maintain = absl::crc32c_t{}; @@ -149,7 +149,7 @@ TEST(SecretDataWithCrcBytesField, InvalidVarint) { TEST(SecretDataWithCrcBytesField, ExistingCRCIsExtendedWhenParsing) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; - s.secret_with_crc = SecretDataWithCrc("before"); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc("before"); std::string bytes = absl::StrCat(/* 10 bytes */ HexDecodeOrDie("0a"), "1234567890XYZ"); @@ -170,7 +170,7 @@ TEST(SecretDataWithCrcBytesField, ExistingCRCIsExtendedWhenParsing) { TEST(SecretDataWithCrcBytesField, SerializeEmpty) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; - s.secret_with_crc = SecretDataWithCrc(""); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc(""); std::string buffer = "BUFFERBUFFERBUFFER"; absl::crc32c_t crc{}; @@ -183,7 +183,7 @@ TEST(SecretDataWithCrcBytesField, SerializeEmpty) { TEST(SecretDataWithCrcBytesField, SerializeRequiresCrc) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; - s.secret_with_crc = SecretDataWithCrc(""); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc(""); std::string buffer = "BUFFERBUFFERBUFFER"; SerializationState state = SerializationState(absl::MakeSpan(buffer)); @@ -194,7 +194,7 @@ TEST(SecretDataWithCrcBytesField, SerializeNonEmpty) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; std::string text = "this is some text"; - s.secret_with_crc = SecretDataWithCrc(text); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc(text); std::string buffer = "BUFFERBUFFERBUFFERBUFFER"; absl::crc32c_t crc{}; @@ -236,7 +236,7 @@ TEST(SecretDataWithCrcBytesField, SerializeTooSmallBuffer) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; std::string text = "this is some text"; - s.secret_with_crc = SecretDataWithCrc(text); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc(text); std::string buffer = "BUFFERBUFFERBUFFE"; absl::crc32c_t crc{}; @@ -249,7 +249,7 @@ TEST(SecretDataWithCrcBytesField, SerializeMuchTooSmallBuffer) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; std::string text = "this is some text"; - s.secret_with_crc = SecretDataWithCrc(text); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc(text); std::string buffer = ""; absl::crc32c_t crc{}; @@ -263,7 +263,7 @@ TEST(SecretDataWithCrcBytesField, ExistingCrcIsExtended) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; std::string text = "this is some text"; - s.secret_with_crc = SecretDataWithCrc(text); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc(text); std::string buffer = "BUFFERBUFFERBUFFERBUFFER"; absl::crc32c_t crc = absl::ComputeCrc32c("existing"); @@ -281,9 +281,9 @@ TEST(SecretDataWithCrcBytesField, ExistingCrcIsExtended) { TEST(SecretDataWithCrcBytesField, RequiresSerialization) { SecretDataWithCrcField field(1, &ParsedStruct::secret_with_crc); ParsedStruct s; - s.secret_with_crc = SecretDataWithCrc(""); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc(""); EXPECT_THAT(field.RequiresSerialization(s), IsFalse()); - s.secret_with_crc = SecretDataWithCrc("this is some text"); + s.secret_with_crc = SecretDataWithCrc::WithComputedCrc("this is some text"); EXPECT_THAT(field.RequiresSerialization(s), IsTrue()); } diff --git a/tink/internal/proto_parser_test.cc b/tink/internal/proto_parser_test.cc index 99795abc..78f2b72b 100644 --- a/tink/internal/proto_parser_test.cc +++ b/tink/internal/proto_parser_test.cc @@ -922,7 +922,8 @@ TEST(ProtoParserTest, SerializeSecredDataFieldAlwaysSerializeWorks) { TEST(ProtoParserTest, SingleBytesFieldSecretDataWithCrcSerializingWorks) { ParsedStruct parsed_struct; - parsed_struct.secret_data_with_crc_member_1 = SecretDataWithCrc("some text"); + parsed_struct.secret_data_with_crc_member_1 = + SecretDataWithCrc::WithComputedCrc("some text"); absl::StatusOr> parser = ProtoParserBuilder() @@ -941,9 +942,10 @@ TEST(ProtoParserTest, SingleBytesFieldSecretDataWithCrcSerializingWorks) { TEST(ProtoParserTest, TwoBytesFieldSecretDataWithCrcSerializingWorks) { ParsedStruct parsed_struct; - parsed_struct.secret_data_with_crc_member_1 = SecretDataWithCrc("some text"); + parsed_struct.secret_data_with_crc_member_1 = + SecretDataWithCrc::WithComputedCrc("some text"); parsed_struct.secret_data_with_crc_member_2 = - SecretDataWithCrc("another text"); + SecretDataWithCrc::WithComputedCrc("another text"); absl::StatusOr> parser = ProtoParserBuilder() @@ -997,9 +999,9 @@ TEST(ProtoParserTest, CrcOfInnerFieldSerializationWorks) { std::string text1 = "something"; std::string text2 = "anything, does not matter"; parsed_struct.inner_member_1.secret_data_with_crc_member_1 = - SecretDataWithCrc(text1); + SecretDataWithCrc::WithComputedCrc(text1); parsed_struct.inner_member_2.secret_data_with_crc_member_1 = - SecretDataWithCrc(text2); + SecretDataWithCrc::WithComputedCrc(text2); absl::StatusOr> parser = ProtoParserBuilder()