blob: e3e73fe6091cc360b07c188366ecf94c4b820357 [file] [log] [blame]
Avi Drissman64595482022-09-14 20:52:291// Copyright 2017 The Chromium Authors
Bence Békyd5c16edf2017-08-04 17:32:302// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_BASE_HEX_UTILS_H_
6#define NET_BASE_HEX_UTILS_H_
7
8#include <string>
9
10#include "base/strings/string_piece.h"
11#include "net/base/net_export.h"
12
13namespace net {
14
Bence Békybb49f0c2021-04-29 12:52:1315// Use base::HexEncode() for encoding to hex representation.
16
17// Decode a hex representation like "666f6f" to a string like "foo". Crashes on
18// invalid input in debug builds, therefore it must only be used on sanitized
19// input (like a constant literal). If validity of input needs to be checked or
20// partial decoding is desired, use base::HexStringToString() instead.
21NET_EXPORT_PRIVATE std::string HexDecode(base::StringPiece hex);
22
Bence Békyd5c16edf2017-08-04 17:32:3023// Return a std::string containing hex and ASCII representations of the binary
24// buffer |input|, with offsets at the beginning of each line, in the style of
25// hexdump. Non-printable characters will be shown as '.' in the ASCII output.
26// Example output:
27// "0x0000: 0090 69bd 5400 000d 610f 0189 0800 4500 ..i.T...a.....E.\n"
28// "0x0010: 001c fb98 4000 4001 7e18 d8ef 2301 455d ....@.@.~...#.E]\n"
29// "0x0020: 7fe2 0800 6bcb 0bc6 806e ....k....n\n"
30NET_EXPORT_PRIVATE std::string HexDump(base::StringPiece input);
31
32} // namespace net
33
34#endif // NET_BASE_HEX_UTILS_H_