/workdir/bitcoin/src/uint256.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | | // Copyright (c) 2009-2020 The Bitcoin Core developers |
3 | | // Distributed under the MIT software license, see the accompanying |
4 | | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | | |
6 | | #include <uint256.h> |
7 | | |
8 | | #include <util/strencodings.h> |
9 | | |
10 | | template <unsigned int BITS> |
11 | | std::string base_blob<BITS>::GetHex() const |
12 | 0 | { |
13 | 0 | uint8_t m_data_rev[WIDTH]; |
14 | 0 | for (int i = 0; i < WIDTH; ++i) { Branch (14:21): [True: 0, False: 0]
Branch (14:21): [True: 0, False: 0]
|
15 | 0 | m_data_rev[i] = m_data[WIDTH - 1 - i]; |
16 | 0 | } |
17 | 0 | return HexStr(m_data_rev); |
18 | 0 | } Unexecuted instantiation: base_blob<160u>::GetHex[abi:cxx11]() const Unexecuted instantiation: base_blob<256u>::GetHex[abi:cxx11]() const |
19 | | |
20 | | template <unsigned int BITS> |
21 | | void base_blob<BITS>::SetHexDeprecated(const std::string_view str) |
22 | 0 | { |
23 | 0 | std::fill(m_data.begin(), m_data.end(), 0); |
24 | |
|
25 | 0 | const auto trimmed = util::RemovePrefixView(util::TrimStringView(str), "0x"); |
26 | | |
27 | | // Note: if we are passed a greater number of digits than would fit as bytes |
28 | | // in m_data, we will be discarding the leftmost ones. |
29 | | // str="12bc" in a WIDTH=1 m_data => m_data[] == "\0xbc", not "0x12". |
30 | 0 | size_t digits = 0; |
31 | 0 | for (const char c : trimmed) { Branch (31:23): [True: 0, False: 0]
Branch (31:23): [True: 0, False: 0]
|
32 | 0 | if (::HexDigit(c) == -1) break; Branch (32:13): [True: 0, False: 0]
Branch (32:13): [True: 0, False: 0]
|
33 | 0 | ++digits; |
34 | 0 | } |
35 | 0 | unsigned char* p1 = m_data.data(); |
36 | 0 | unsigned char* pend = p1 + WIDTH; |
37 | 0 | while (digits > 0 && p1 < pend) { Branch (37:12): [True: 0, False: 0]
Branch (37:26): [True: 0, False: 0]
Branch (37:12): [True: 0, False: 0]
Branch (37:26): [True: 0, False: 0]
|
38 | 0 | *p1 = ::HexDigit(trimmed[--digits]); |
39 | 0 | if (digits > 0) { Branch (39:13): [True: 0, False: 0]
Branch (39:13): [True: 0, False: 0]
|
40 | 0 | *p1 |= ((unsigned char)::HexDigit(trimmed[--digits]) << 4); |
41 | 0 | p1++; |
42 | 0 | } |
43 | 0 | } |
44 | 0 | } Unexecuted instantiation: base_blob<160u>::SetHexDeprecated(std::basic_string_view<char, std::char_traits<char> >) Unexecuted instantiation: base_blob<256u>::SetHexDeprecated(std::basic_string_view<char, std::char_traits<char> >) |
45 | | |
46 | | template <unsigned int BITS> |
47 | | std::string base_blob<BITS>::ToString() const |
48 | 0 | { |
49 | 0 | return (GetHex()); |
50 | 0 | } Unexecuted instantiation: base_blob<160u>::ToString[abi:cxx11]() const Unexecuted instantiation: base_blob<256u>::ToString[abi:cxx11]() const |
51 | | |
52 | | // Explicit instantiations for base_blob<160> |
53 | | template std::string base_blob<160>::GetHex() const; |
54 | | template std::string base_blob<160>::ToString() const; |
55 | | template void base_blob<160>::SetHexDeprecated(std::string_view); |
56 | | |
57 | | // Explicit instantiations for base_blob<256> |
58 | | template std::string base_blob<256>::GetHex() const; |
59 | | template std::string base_blob<256>::ToString() const; |
60 | | template void base_blob<256>::SetHexDeprecated(std::string_view); |
61 | | |
62 | | const uint256 uint256::ZERO(0); |
63 | | const uint256 uint256::ONE(1); |