/Users/eugenesiegel/btc/bitcoin/src/crypto/hex_base.cpp
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | // Copyright (c) 2009-present The Bitcoin Core developers | 
| 2 |  | // Distributed under the MIT software license, see the accompanying | 
| 3 |  | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | 
| 4 |  |  | 
| 5 |  | #include <crypto/hex_base.h> | 
| 6 |  |  | 
| 7 |  | #include <array> | 
| 8 |  | #include <cstring> | 
| 9 |  | #include <string> | 
| 10 |  |  | 
| 11 |  | namespace { | 
| 12 |  |  | 
| 13 |  | using ByteAsHex = std::array<char, 2>; | 
| 14 |  |  | 
| 15 |  | constexpr std::array<ByteAsHex, 256> CreateByteToHexMap() | 
| 16 | 0 | { | 
| 17 | 0 |     constexpr char hexmap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; | 
| 18 | 0 | 
 | 
| 19 | 0 |     std::array<ByteAsHex, 256> byte_to_hex{}; | 
| 20 | 0 |     for (size_t i = 0; i < byte_to_hex.size(); ++i) { | 
| 21 | 0 |         byte_to_hex[i][0] = hexmap[i >> 4]; | 
| 22 | 0 |         byte_to_hex[i][1] = hexmap[i & 15]; | 
| 23 | 0 |     } | 
| 24 | 0 |     return byte_to_hex; | 
| 25 | 0 | } | 
| 26 |  |  | 
| 27 |  | } // namespace | 
| 28 |  |  | 
| 29 |  | std::string HexStr(const std::span<const uint8_t> s) | 
| 30 | 1.29M | { | 
| 31 | 1.29M |     std::string rv(s.size() * 2, '\0'); | 
| 32 | 1.29M |     static constexpr auto byte_to_hex = CreateByteToHexMap(); | 
| 33 | 1.29M |     static_assert(sizeof(byte_to_hex) == 512); | 
| 34 |  |  | 
| 35 | 1.29M |     char* it = rv.data(); | 
| 36 | 36.7M |     for (uint8_t v : s) { | 
| 37 | 36.7M |         std::memcpy(it, byte_to_hex[v].data(), 2); | 
| 38 | 36.7M |         it += 2; | 
| 39 | 36.7M |     } | 
| 40 |  |  | 
| 41 | 1.29M |     assert(it == rv.data() + rv.size()); | 
| 42 | 1.29M |     return rv; | 
| 43 | 1.29M | } | 
| 44 |  |  | 
| 45 |  | const signed char p_util_hexdigit[256] = | 
| 46 |  | { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 47 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 48 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 49 |  |   0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1, | 
| 50 |  |   -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 51 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 52 |  |   -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 53 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 54 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 55 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 56 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 57 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 58 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 59 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 60 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | 
| 61 |  |   -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, }; | 
| 62 |  |  | 
| 63 |  | signed char HexDigit(char c) | 
| 64 | 0 | { | 
| 65 | 0 |     return p_util_hexdigit[(unsigned char)c]; | 
| 66 | 0 | } | 
| 67 |  |  |