Commit 265431e0 authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Remove net::HexDecode() in favor of base::HexStringToString().

Bug: 1021236
Change-Id: Ib6d9239de1291281fd01fd683b9df88fc6427085
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1898623Reviewed-by: default avatarMatt Mueller <mattm@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Auto-Submit: Eric Roman <eroman@chromium.org>
Commit-Queue: Eric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713578}
parent d74f1ac4
......@@ -72,7 +72,6 @@
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "google_apis/drive/auth_service.h"
#include "net/base/hex_utils.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "storage/common/file_system/file_system_types.h"
#include "storage/common/file_system/file_system_util.h"
......@@ -1093,7 +1092,10 @@ FileManagerPrivateDetectCharacterEncodingFunction::Run() {
const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
std::string input = net::HexDecode(params->bytes);
std::string input;
if (!base::HexStringToString(params->bytes, &input))
input.clear();
std::string encoding;
bool success = base::DetectEncoding(input, &encoding);
return RespondNow(OneArgument(std::make_unique<base::Value>(
......
......@@ -5,22 +5,11 @@
#include "net/base/hex_utils.h"
#include <algorithm>
#include <cstdint>
#include <vector>
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
namespace net {
std::string HexDecode(base::StringPiece input) {
std::vector<uint8_t> output;
std::string result;
if (base::HexStringToBytes(input, &output))
result.assign(reinterpret_cast<const char*>(output.data()), output.size());
return result;
}
std::string HexDump(base::StringPiece input) {
const int kBytesPerLine = 16; // Maximum bytes dumped per line.
int offset = 0;
......
......@@ -12,11 +12,6 @@
namespace net {
// Return a std::string of binary data represented by the hex string |input|.
// For example, HexDecode("48656c6c6f20776f726c6421") == "Hello world!"
// This is the inverse function of base::HexEncode().
NET_EXPORT_PRIVATE std::string HexDecode(base::StringPiece input);
// Return a std::string containing hex and ASCII representations of the binary
// buffer |input|, with offsets at the beginning of each line, in the style of
// hexdump. Non-printable characters will be shown as '.' in the ASCII output.
......
......@@ -9,13 +9,6 @@ namespace net {
namespace test {
TEST(HexUtilsTest, HexDecode) {
EXPECT_EQ("", HexDecode(""));
EXPECT_EQ("a", HexDecode("61"));
// Mixed case input.
EXPECT_EQ("Hello world!", HexDecode("48656c6C6F20776f726C6421"));
}
TEST(HexUtilsTest, HexDump) {
EXPECT_EQ("", HexDump(""));
EXPECT_EQ("0x0000: 4865 6c6c 6f20 776f 726c 6421 Hello.world!\n",
......@@ -26,11 +19,11 @@ TEST(HexUtilsTest, HexDump) {
HexDump("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"));
// Verify that 0x21 and 0x7e are printable, 0x20 and 0x7f are not.
EXPECT_EQ("0x0000: 2021 7e7f .!~.\n",
HexDump(HexDecode("20217e7f")));
HexDump("\x20\x21\x7e\x7f"));
// Verify that values above numeric_limits<unsigned char>::max() are cast
// properly on platforms where char is unsigned.
EXPECT_EQ("0x0000: 90aa ff ...\n",
HexDump(HexDecode("90aaff")));
HexDump("\x90\xaa\xff"));
}
} // namespace test
......
......@@ -155,10 +155,9 @@ const AuditProofTestVector kAuditProofs[] = {
// Decodes a hexadecimal string into the binary data it represents.
std::string HexToBytes(const std::string& hex_data) {
std::vector<uint8_t> output;
std::string result;
if (base::HexStringToBytes(hex_data, &output))
result.assign(output.begin(), output.end());
if (!base::HexStringToString(hex_data, &result))
result.clear();
return result;
}
......
......@@ -1337,11 +1337,10 @@ TEST_P(X509CertificateNameVerifyTest, VerifyHostname) {
ASSERT_NE(0U, addr_ascii.length());
if (addr_ascii[0] == 'x') { // Hex encoded address
addr_ascii.erase(0, 1);
std::vector<uint8_t> bytes;
EXPECT_TRUE(base::HexStringToBytes(addr_ascii, &bytes))
std::string bytes;
EXPECT_TRUE(base::HexStringToString(addr_ascii, &bytes))
<< "Could not parse hex address " << addr_ascii << " i = " << i;
ip_addressses.push_back(
std::string(reinterpret_cast<char*>(bytes.data()), bytes.size()));
ip_addressses.push_back(std::move(bytes));
ASSERT_EQ(16U, ip_addressses.back().size()) << i;
} else { // Decimal groups
std::vector<std::string> decimals_ascii = base::SplitString(
......
......@@ -41,7 +41,10 @@ inline std::string Http2HexEncodeImpl(const void* bytes, size_t size) {
}
inline std::string Http2HexDecodeImpl(Http2StringPiece data) {
return net::HexDecode(data);
std::string result;
if (!base::HexStringToString(data, &result))
result.clear();
return result;
}
inline std::string Http2HexDumpImpl(Http2StringPiece data) {
......
......@@ -87,9 +87,12 @@ class QuicTextUtilsImpl {
}
// Converts |data| from a hexadecimal ASCII string to a binary string
// that is |data.length()/2| bytes long.
// that is |data.length()/2| bytes long. On failure returns empty string.
static std::string HexDecode(QuicStringPiece data) {
return net::HexDecode(data);
std::string result;
if (!base::HexStringToString(data, &result))
result.clear();
return result;
}
// Base64 encodes with no padding |data_len| bytes of |data| into |output|.
......
......@@ -35,7 +35,10 @@ inline char SpdyHexDigitToIntImpl(char c) {
}
inline std::string SpdyHexDecodeImpl(SpdyStringPiece data) {
return net::HexDecode(data);
std::string result;
if (!base::HexStringToString(data, &result))
result.clear();
return result;
}
NET_EXPORT_PRIVATE bool SpdyHexDecodeToUInt32Impl(SpdyStringPiece data,
......
......@@ -164,6 +164,13 @@ const char kSampleSTHTreeHeadSignature[] =
"d3";
size_t kSampleSTHTreeSize = 21u;
std::string HexDecode(base::StringPiece input) {
std::string result;
if (!base::HexStringToString(input, &result))
result.clear();
return result;
}
} // namespace
void GetX509CertSignedEntry(SignedEntryData* entry) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment