| 46 | } |
| 47 | |
| 48 | void from_hex_or_throw(const std::string &text, void *data, size_t buffer_size) { |
| 49 | if (text.size() != buffer_size * 2) |
| 50 | throw std::runtime_error("from_hex: Wrong string size (" + common::to_string(text.size()) + ") must be " + |
| 51 | common::to_string(buffer_size * 2)); |
| 52 | for (size_t i = 0; i < buffer_size; ++i) |
| 53 | static_cast<uint8_t *>(data)[i] = (from_hex(text[i * 2]) << 4) | from_hex(text[i * 2 + 1]); |
| 54 | } |
| 55 | |
| 56 | bool from_hex(const std::string &text, void *data, size_t buffer_size) { |
| 57 | if (text.size() != buffer_size * 2) |