hex_utils.h 1.3 KB

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