Bitcoin Core  24.99.0
P2P Digital Currency
key_io.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020-2021 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 <chainparams.h>
6 #include <key_io.h>
7 #include <test/fuzz/fuzz.h>
8 
9 #include <cassert>
10 #include <cstdint>
11 #include <string>
12 #include <vector>
13 
15 {
16  ECC_Start();
18 }
19 
21 {
22  const std::string random_string(buffer.begin(), buffer.end());
23 
24  const CKey key = DecodeSecret(random_string);
25  if (key.IsValid()) {
26  assert(key == DecodeSecret(EncodeSecret(key)));
27  }
28 
29  const CExtKey ext_key = DecodeExtKey(random_string);
30  if (ext_key.key.size() == 32) {
31  assert(ext_key == DecodeExtKey(EncodeExtKey(ext_key)));
32  }
33 
34  const CExtPubKey ext_pub_key = DecodeExtPubKey(random_string);
35  if (ext_pub_key.pubkey.size() == CPubKey::COMPRESSED_SIZE) {
36  assert(ext_pub_key == DecodeExtPubKey(EncodeExtPubKey(ext_pub_key)));
37  }
38 }
ECC_Start()
Definition: key.cpp:391
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
static const std::string MAIN
Chain name strings.
An encapsulated private key.
Definition: key.h:27
unsigned int size() const
Simple read-only vector-like interface.
Definition: key.h:87
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:93
static constexpr unsigned int COMPRESSED_SIZE
Definition: pubkey.h:40
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
Definition: pubkey.h:112
std::string EncodeExtKey(const CExtKey &key)
Definition: key_io.cpp:265
CExtPubKey DecodeExtPubKey(const std::string &str)
Definition: key_io.cpp:229
std::string EncodeSecret(const CKey &key)
Definition: key_io.cpp:216
CKey DecodeSecret(const std::string &str)
Definition: key_io.cpp:198
std::string EncodeExtPubKey(const CExtPubKey &key)
Definition: key_io.cpp:242
CExtKey DecodeExtKey(const std::string &str)
Definition: key_io.cpp:252
Definition: key.h:161
CKey key
Definition: key.h:166
CPubKey pubkey
Definition: pubkey.h:300
FUZZ_TARGET_INIT(key_io, initialize_key_io)
Definition: key_io.cpp:20
void initialize_key_io()
Definition: key_io.cpp:14
assert(!tx.IsCoinBase())