xref: /aosp_15_r20/external/cronet/net/base/hex_utils.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2017 The Chromium Authors
2 // 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 #include <string_view>
10 
11 #include "net/base/net_export.h"
12 
13 namespace net {
14 
15 // 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.
21 NET_EXPORT_PRIVATE std::string HexDecode(std::string_view hex);
22 
23 // 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"
30 NET_EXPORT_PRIVATE std::string HexDump(std::string_view input);
31 
32 }  // namespace net
33 
34 #endif  // NET_BASE_HEX_UTILS_H_
35