7 #include <packager/utils/hex_parser.h>
9 #include <absl/strings/escaping.h>
10 #include <absl/types/span.h>
14 void HexStringToBytes(
const std::string& hex, std::vector<uint8_t>* bytes) {
15 std::string raw = absl::HexStringToBytes(hex);
17 absl::string_view str_view(raw);
18 absl::Span<const uint8_t> span(
19 reinterpret_cast<const uint8_t*
>(str_view.data()), str_view.size());
20 *bytes = std::vector<uint8_t>(span.begin(), span.end());
23 bool ValidHexStringToBytes(
const std::string& hex,
24 std::vector<uint8_t>* bytes) {
26 if (!ValidHexStringToBytes(hex, &raw))
29 absl::string_view str_view(raw);
30 absl::Span<const uint8_t> span(
31 reinterpret_cast<const uint8_t*
>(str_view.data()), str_view.size());
32 *bytes = std::vector<uint8_t>(span.begin(), span.end());
36 bool ValidHexStringToBytes(
const std::string& hex, std::string* bytes) {
41 c =
static_cast<char>(std::tolower(c));
42 if ((c >=
'0' && c <=
'9') || (c >=
'a' && c <=
'f')) {
49 *bytes = absl::HexStringToBytes(hex);
All the methods that are virtual are virtual for mocking.