Replace deprecated version of absl::HexStringToBytes in quiche/oblivious_http tests Replaces the deprecated version of absl::HexStringToBytes that returns std::string with the version that returns bool and populates a passed in std::string. This CL is not expected to introduce any changes in functionality other than now verifying that the call to absl::HexStringToBytes was successful. This allows the Chrome build of QUICHE to build without the `-Wno-deprecated-declarations` clang flag. PiperOrigin-RevId: 619215781
diff --git a/quiche/oblivious_http/buffers/oblivious_http_response_test.cc b/quiche/oblivious_http/buffers/oblivious_http_response_test.cc index 4178c73..4ff5f50 100644 --- a/quiche/oblivious_http/buffers/oblivious_http_response_test.cc +++ b/quiche/oblivious_http/buffers/oblivious_http_response_test.cc
@@ -23,25 +23,34 @@ std::string GetHpkePrivateKey() { absl::string_view hpke_key_hex = "b77431ecfa8f4cfc30d6e467aafa06944dffe28cb9dd1409e33a3045f5adc8a1"; - return absl::HexStringToBytes(hpke_key_hex); + std::string hpke_key_bytes; + EXPECT_TRUE(absl::HexStringToBytes(hpke_key_hex, &hpke_key_bytes)); + return hpke_key_bytes; } std::string GetHpkePublicKey() { absl::string_view public_key = "6d21cfe09fbea5122f9ebc2eb2a69fcc4f06408cd54aac934f012e76fcdcef62"; - return absl::HexStringToBytes(public_key); + std::string public_key_bytes; + EXPECT_TRUE(absl::HexStringToBytes(public_key, &public_key_bytes)); + return public_key_bytes; } std::string GetSeed() { absl::string_view seed = "52c4a758a802cd8b936eceea314432798d5baf2d7e9235dc084ab1b9cfa2f736"; - return absl::HexStringToBytes(seed); + std::string seed_bytes; + EXPECT_TRUE(absl::HexStringToBytes(seed, &seed_bytes)); + return seed_bytes; } std::string GetSeededEncapsulatedKey() { absl::string_view encapsulated_key = "37fda3567bdbd628e88668c3c8d7e97d1d1253b6d4ea6d44c150f741f1bf4431"; - return absl::HexStringToBytes(encapsulated_key); + std::string encapsulated_key_bytes; + EXPECT_TRUE( + absl::HexStringToBytes(encapsulated_key, &encapsulated_key_bytes)); + return encapsulated_key_bytes; } const ObliviousHttpHeaderKeyConfig GetOhttpKeyConfig(uint8_t key_id, @@ -151,13 +160,16 @@ absl::string_view encrypted_response = "39d5b03c02c97e216df444e4681007105974d4df1585aae05e7b53f3ccdb55d51f711d48" "eeefbc1a555d6d928e35df33fd23c23846fa7b083e30692f7b"; + std::string encrypted_response_bytes; + ASSERT_TRUE( + absl::HexStringToBytes(encrypted_response, &encrypted_response_bytes)); auto oblivious_context = SetUpObliviousHttpContext(4, EVP_HPKE_DHKEM_X25519_HKDF_SHA256, EVP_HPKE_HKDF_SHA256, EVP_HPKE_AES_256_GCM, "test") .ReleaseContext(); auto decapsulated = ObliviousHttpResponse::CreateClientObliviousResponse( - absl::HexStringToBytes(encrypted_response), oblivious_context); + std::move(encrypted_response_bytes), oblivious_context); EXPECT_TRUE(decapsulated.ok()); auto decrypted = decapsulated->GetPlaintextData(); EXPECT_EQ(decrypted, "test response"); @@ -203,10 +215,13 @@ 'z')); absl::string_view expected_encrypted_response = "2a3271ac4e6a501f51d0264d3dd7d0bc8a06973b58e89c26d6dac06144"; + std::string expected_encrypted_response_bytes; + ASSERT_TRUE(absl::HexStringToBytes(expected_encrypted_response, + &expected_encrypted_response_bytes)); EXPECT_EQ( server_response_encapsulate->EncapsulateAndSerialize().substr( GetResponseNonceLength(*(server_request_context.hpke_context_))), - absl::HexStringToBytes(expected_encrypted_response)); + expected_encrypted_response_bytes); } } // namespace quiche
diff --git a/quiche/oblivious_http/common/oblivious_http_header_key_config_test.cc b/quiche/oblivious_http/common/oblivious_http_header_key_config_test.cc index f9a8348..40d8cf4 100644 --- a/quiche/oblivious_http/common/oblivious_http_header_key_config_test.cc +++ b/quiche/oblivious_http/common/oblivious_http_header_key_config_test.cc
@@ -191,11 +191,13 @@ } TEST(ObliviousHttpKeyConfigs, TwoSimilarKeyConfigs) { - std::string key = absl::HexStringToBytes( + std::string key; + ASSERT_TRUE(absl::HexStringToBytes( "4b0020f83e0a17cbdb18d2684dd2a9b087a43e5f3fa3fa27a049bc746a6e97a1e0244b00" "0400010002" // Intentional concatenation "4f0020f83e0a17cbdb18d2684dd2a9b087a43e5f3fa3fa27a049bc746a6e97a1e0244b00" - "0400010001"); + "0400010001", + &key)); EXPECT_THAT(ObliviousHttpKeyConfigs::ParseConcatenatedKeys(key).value(), Property(&ObliviousHttpKeyConfigs::NumKeys, 2)); EXPECT_THAT( @@ -205,27 +207,34 @@ } TEST(ObliviousHttpKeyConfigs, RFCExample) { - std::string key = absl::HexStringToBytes( + std::string key; + ASSERT_TRUE(absl::HexStringToBytes( "01002031e1f05a740102115220e9af918f738674aec95f54db6e04eb705aae8e79815500" - "080001000100010003"); + "080001000100010003", + &key)); auto configs = ObliviousHttpKeyConfigs::ParseConcatenatedKeys(key).value(); EXPECT_THAT(configs, Property(&ObliviousHttpKeyConfigs::NumKeys, 1)); EXPECT_THAT( configs.PreferredConfig(), AllOf(HasKeyId(0x01), HasKemId(EVP_HPKE_DHKEM_X25519_HKDF_SHA256), HasKdfId(EVP_HPKE_HKDF_SHA256), HasAeadId(EVP_HPKE_AES_128_GCM))); + std::string expected_public_key; + ASSERT_TRUE(absl::HexStringToBytes( + "31e1f05a740102115220e9af918f738674aec95f54db6e04eb705aae8e798155", + &expected_public_key)); EXPECT_THAT( configs.GetPublicKeyForId(configs.PreferredConfig().GetKeyId()).value(), - StrEq(absl::HexStringToBytes( - "31e1f05a740102115220e9af918f738674aec95f54db6e04eb705aae8e798155"))); + StrEq(expected_public_key)); } TEST(ObliviousHttpKeyConfigs, DuplicateKeyId) { - std::string key = absl::HexStringToBytes( + std::string key; + ASSERT_TRUE(absl::HexStringToBytes( "4b0020f83e0a17cbdb18d2684dd2a9b087a43e5f3fa3fa27a049bc746a6e97a1e0244b00" "0400010002" // Intentional concatenation "4b0020f83e0a17cbdb18d2684dd2a9b087a43e5f3fa3fb27a049bc746a6e97a1e0244b00" - "0400010001"); + "0400010001", + &key)); EXPECT_FALSE(ObliviousHttpKeyConfigs::ParseConcatenatedKeys(key).ok()); }