Bitcoin Core  22.99.0
P2P Digital Currency
hex.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 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 <core_io.h>
6 #include <primitives/block.h>
7 #include <pubkey.h>
8 #include <rpc/util.h>
9 #include <test/fuzz/fuzz.h>
10 #include <uint256.h>
11 #include <univalue.h>
12 #include <util/strencodings.h>
13 
14 #include <cassert>
15 #include <cstdint>
16 #include <string>
17 #include <vector>
18 
20 {
21  static const ECCVerifyHandle verify_handle;
22 }
23 
25 {
26  const std::string random_hex_string(buffer.begin(), buffer.end());
27  const std::vector<unsigned char> data = ParseHex(random_hex_string);
28  const std::string hex_data = HexStr(data);
29  if (IsHex(random_hex_string)) {
30  assert(ToLower(random_hex_string) == hex_data);
31  }
32  (void)IsHexNumber(random_hex_string);
33  uint256 result;
34  (void)ParseHashStr(random_hex_string, result);
35  (void)uint256S(random_hex_string);
36  try {
37  (void)HexToPubKey(random_hex_string);
38  } catch (const UniValue&) {
39  }
40  CBlockHeader block_header;
41  (void)DecodeHexBlockHeader(block_header, random_hex_string);
42  CBlock block;
43  (void)DecodeHexBlk(block, random_hex_string);
44 }
block.h
ParseHashStr
bool ParseHashStr(const std::string &strHex, uint256 &result)
Parse a hex string into 256 bits.
Definition: core_read.cpp:239
ParseHex
std::vector< unsigned char > ParseHex(const char *psz)
Definition: strencodings.cpp:84
assert
assert(!tx.IsCoinBase())
initialize_hex
void initialize_hex()
Definition: hex.cpp:19
IsHexNumber
bool IsHexNumber(const std::string &str)
Return true if the string is a hex number, optionally prefixed with "0x".
Definition: strencodings.cpp:71
CBlockHeader
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:20
uint256.h
IsHex
bool IsHex(const std::string &str)
Definition: strencodings.cpp:61
HexToPubKey
CPubKey HexToPubKey(const std::string &hex_in)
Definition: util.cpp:191
pubkey.h
core_io.h
UniValue
Definition: univalue.h:19
strencodings.h
univalue.h
DecodeHexBlockHeader
bool DecodeHexBlockHeader(CBlockHeader &, const std::string &hex_header)
Definition: core_read.cpp:208
uint256
256-bit opaque blob.
Definition: uint256.h:124
uint256S
uint256 uint256S(const char *str)
Definition: uint256.h:137
CBlock
Definition: block.h:62
ECCVerifyHandle
Users of this module must hold an ECCVerifyHandle.
Definition: pubkey.h:315
fuzz.h
FUZZ_TARGET_INIT
FUZZ_TARGET_INIT(hex, initialize_hex)
Definition: hex.cpp:24
util.h
DecodeHexBlk
bool DecodeHexBlk(CBlock &, const std::string &strHexBlk)
Definition: core_read.cpp:222
HexStr
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Definition: strencodings.cpp:594
ToLower
std::string ToLower(const std::string &str)
Returns the lowercase equivalent of the given string.
Definition: strencodings.cpp:573