| 46 | } |
| 47 | |
| 48 | std::vector<std::byte> hex_string_to_byte_vec(std::string_view hex) |
| 49 | { |
| 50 | std::vector<std::byte> bytes; |
| 51 | bytes.reserve(hex.length() / 2); |
| 52 | |
| 53 | for (size_t i{0}; i < hex.length(); i += 2) { |
| 54 | uint8_t byte_value; |
| 55 | auto [ptr, ec] = std::from_chars(hex.data() + i, hex.data() + i + 2, byte_value, 16); |
| 56 | |
| 57 | if (ec != std::errc{} || ptr != hex.data() + i + 2) { |
| 58 | throw std::invalid_argument("Invalid hex character"); |
| 59 | } |
| 60 | bytes.push_back(static_cast<std::byte>(byte_value)); |
| 61 | } |
| 62 | return bytes; |
| 63 | } |
| 64 | |
| 65 | std::string byte_span_to_hex_string_reversed(std::span<const std::byte> bytes) |
| 66 | { |
no test coverage detected