Bitcoin Core  22.99.0
P2P Digital Currency
key_io.cpp
Go to the documentation of this file.
1 // Copyright (c) 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 <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  static const ECCVerifyHandle verify_handle;
17  ECC_Start();
19 }
20 
22 {
23  const std::string random_string(buffer.begin(), buffer.end());
24 
25  const CKey key = DecodeSecret(random_string);
26  if (key.IsValid()) {
27  assert(key == DecodeSecret(EncodeSecret(key)));
28  }
29 
30  const CExtKey ext_key = DecodeExtKey(random_string);
31  if (ext_key.key.size() == 32) {
32  assert(ext_key == DecodeExtKey(EncodeExtKey(ext_key)));
33  }
34 
35  const CExtPubKey ext_pub_key = DecodeExtPubKey(random_string);
36  if (ext_pub_key.pubkey.size() == CPubKey::COMPRESSED_SIZE) {
37  assert(ext_pub_key == DecodeExtPubKey(EncodeExtPubKey(ext_pub_key)));
38  }
39 }
assert
assert(!tx.IsCoinBase())
initialize_key_io
void initialize_key_io()
Definition: key_io.cpp:14
key_io.h
chainparams.h
EncodeSecret
std::string EncodeSecret(const CKey &key)
Definition: key_io.cpp:196
CExtKey
Definition: key.h:160
EncodeExtKey
std::string EncodeExtKey(const CExtKey &key)
Definition: key_io.cpp:245
CKey::IsValid
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:92
SelectParams
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
Definition: chainparams.cpp:578
DecodeSecret
CKey DecodeSecret(const std::string &str)
Definition: key_io.cpp:178
CPubKey::size
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
Definition: pubkey.h:111
CPubKey::COMPRESSED_SIZE
static constexpr unsigned int COMPRESSED_SIZE
Definition: pubkey.h:39
DecodeExtPubKey
CExtPubKey DecodeExtPubKey(const std::string &str)
Definition: key_io.cpp:209
CBaseChainParams::MAIN
static const std::string MAIN
Chain name strings.
Definition: chainparamsbase.h:22
DecodeExtKey
CExtKey DecodeExtKey(const std::string &str)
Definition: key_io.cpp:232
ECC_Start
void ECC_Start()
Initialize the elliptic curve support.
Definition: key.cpp:370
CKey::size
unsigned int size() const
Simple read-only vector-like interface.
Definition: key.h:87
ECCVerifyHandle
Users of this module must hold an ECCVerifyHandle.
Definition: pubkey.h:315
CKey
An encapsulated private key.
Definition: key.h:26
fuzz.h
EncodeExtPubKey
std::string EncodeExtPubKey(const CExtPubKey &key)
Definition: key_io.cpp:222
CExtPubKey::pubkey
CPubKey pubkey
Definition: pubkey.h:292
CExtPubKey
Definition: pubkey.h:287
CExtKey::key
CKey key
Definition: key.h:165
FUZZ_TARGET_INIT
FUZZ_TARGET_INIT(key_io, initialize_key_io)
Definition: key_io.cpp:21