Repalce QuicheTextUtils::HexEncode/Decode with Abseil equivalents.
PiperOrigin-RevId: 339366305
Change-Id: Ifa155b75569a17f3f3be908c7d0a9f9de7b9474c
diff --git a/common/platform/api/quiche_text_utils.h b/common/platform/api/quiche_text_utils.h
index 5bc5f50..1a11c2a 100644
--- a/common/platform/api/quiche_text_utils.h
+++ b/common/platform/api/quiche_text_utils.h
@@ -7,6 +7,7 @@
#include <string>
+#include "absl/strings/escaping.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_export.h"
@@ -32,32 +33,12 @@
return quiche::QuicheTextUtilsImpl::Uint64ToString(in);
}
- // This converts |length| bytes of binary to a 2*|length|-character
- // hexadecimal representation.
- // Return value: 2*|length| characters of ASCII string.
- static std::string HexEncode(const char* data, size_t length) {
- return HexEncode(absl::string_view(data, length));
- }
-
- // This converts |data.length()| bytes of binary to a
- // 2*|data.length()|-character hexadecimal representation.
- // Return value: 2*|data.length()| characters of ASCII string.
- static std::string HexEncode(absl::string_view data) {
- return quiche::QuicheTextUtilsImpl::HexEncode(data);
- }
-
// This converts a uint32 into an 8-character hexidecimal
// representation. Return value: 8 characters of ASCII string.
static std::string Hex(uint32_t v) {
return quiche::QuicheTextUtilsImpl::Hex(v);
}
- // Converts |data| from a hexadecimal ASCII string to a binary string
- // that is |data.length()/2| bytes long.
- static std::string HexDecode(absl::string_view data) {
- return quiche::QuicheTextUtilsImpl::HexDecode(data);
- }
-
// Base64 encodes with no padding |data_len| bytes of |data| into |output|.
static void Base64Encode(const uint8_t* data,
size_t data_len,
diff --git a/common/platform/api/quiche_text_utils_test.cc b/common/platform/api/quiche_text_utils_test.cc
index 012d33d..f85f8b0 100644
--- a/common/platform/api/quiche_text_utils_test.cc
+++ b/common/platform/api/quiche_text_utils_test.cc
@@ -6,6 +6,7 @@
#include <string>
+#include "absl/strings/escaping.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_test.h"
namespace quiche {
@@ -37,21 +38,6 @@
EXPECT_EQ("1234", quiche::QuicheTextUtils::Uint64ToString(1234));
}
-TEST_F(QuicheTextUtilsTest, HexEncode) {
- EXPECT_EQ("48656c6c6f", quiche::QuicheTextUtils::HexEncode("Hello", 5));
- EXPECT_EQ("48656c6c6f", quiche::QuicheTextUtils::HexEncode("Hello World", 5));
- EXPECT_EQ("48656c6c6f", quiche::QuicheTextUtils::HexEncode("Hello"));
- EXPECT_EQ("0102779cfa",
- quiche::QuicheTextUtils::HexEncode("\x01\x02\x77\x9c\xfa"));
-}
-
-TEST_F(QuicheTextUtilsTest, HexDecode) {
- EXPECT_EQ("Hello", quiche::QuicheTextUtils::HexDecode("48656c6c6f"));
- EXPECT_EQ("", quiche::QuicheTextUtils::HexDecode(""));
- EXPECT_EQ("\x01\x02\x77\x9c\xfa",
- quiche::QuicheTextUtils::HexDecode("0102779cfa"));
-}
-
TEST_F(QuicheTextUtilsTest, HexDump) {
// Verify output of the HexDump method is as expected.
char packet[] = {
@@ -72,14 +58,13 @@
"0x0040: 6c69 6e65 7320 6f66 206f 7574 7075 742e lines.of.output.\n"
"0x0050: 0102 03 ...\n");
// Verify that 0x21 and 0x7e are printable, 0x20 and 0x7f are not.
- EXPECT_EQ("0x0000: 2021 7e7f .!~.\n",
- quiche::QuicheTextUtils::HexDump(
- quiche::QuicheTextUtils::HexDecode("20217e7f")));
+ EXPECT_EQ(
+ "0x0000: 2021 7e7f .!~.\n",
+ quiche::QuicheTextUtils::HexDump(absl::HexStringToBytes("20217e7f")));
// Verify that values above numeric_limits<unsigned char>::max() are formatted
// properly on platforms where char is unsigned.
EXPECT_EQ("0x0000: 90aa ff ...\n",
- quiche::QuicheTextUtils::HexDump(
- quiche::QuicheTextUtils::HexDecode("90aaff")));
+ quiche::QuicheTextUtils::HexDump(absl::HexStringToBytes("90aaff")));
}
TEST_F(QuicheTextUtilsTest, Base64Encode) {