| 179 | } |
| 180 | |
| 181 | std::optional<std::vector<u8>> DecodeHex(const std::string_view in) |
| 182 | { |
| 183 | std::vector<u8> data; |
| 184 | data.reserve(in.size() / 2); |
| 185 | |
| 186 | for (size_t i = 0; i < in.size() / 2; i++) |
| 187 | { |
| 188 | std::optional<u8> byte = StringUtil::FromChars<u8>(in.substr(i * 2, 2), 16); |
| 189 | if (byte.has_value()) |
| 190 | data.push_back(*byte); |
| 191 | else |
| 192 | return std::nullopt; |
| 193 | } |
| 194 | |
| 195 | return {data}; |
| 196 | } |
| 197 | |
| 198 | std::string EncodeHex(const u8* data, int length) |
| 199 | { |