Avi Drissman | 6459548 | 2022-09-14 20:52:29 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
Bence Béky | d5c16edf | 2017-08-04 17:32:30 | [diff] [blame] | 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 | |
| 10 | #include "base/strings/string_piece.h" |
| 11 | #include "net/base/net_export.h" |
| 12 | |
| 13 | namespace net { |
| 14 | |
Bence Béky | bb49f0c | 2021-04-29 12:52:13 | [diff] [blame] | 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(base::StringPiece hex); |
| 22 | |
Bence Béky | d5c16edf | 2017-08-04 17:32:30 | [diff] [blame] | 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(base::StringPiece input); |
| 31 | |
| 32 | } // namespace net |
| 33 | |
| 34 | #endif // NET_BASE_HEX_UTILS_H_ |