2021-12-30 19:36:57 +02:00
|
|
|
// Copyright (c) 2019-2021 The Bitcoin Core developers
|
2019-10-23 12:37:59 +00:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <test/fuzz/fuzz.h>
|
|
|
|
|
|
|
|
#include <base58.h>
|
2020-03-11 12:05:52 +00:00
|
|
|
#include <psbt.h>
|
2019-10-23 12:37:59 +00:00
|
|
|
#include <util/strencodings.h>
|
2020-04-16 13:11:54 -04:00
|
|
|
#include <util/string.h>
|
2019-10-23 12:37:59 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-06-18 23:13:07 +00:00
|
|
|
void initialize_base_encode_decode()
|
|
|
|
{
|
|
|
|
static const ECCVerifyHandle verify_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
FUZZ_TARGET_INIT(base_encode_decode, initialize_base_encode_decode)
|
2019-10-23 12:37:59 +00:00
|
|
|
{
|
|
|
|
const std::string random_encoded_string(buffer.begin(), buffer.end());
|
|
|
|
|
|
|
|
std::vector<unsigned char> decoded;
|
|
|
|
if (DecodeBase58(random_encoded_string, decoded, 100)) {
|
|
|
|
const std::string encoded_string = EncodeBase58(decoded);
|
|
|
|
assert(encoded_string == TrimString(encoded_string));
|
|
|
|
assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DecodeBase58Check(random_encoded_string, decoded, 100)) {
|
|
|
|
const std::string encoded_string = EncodeBase58Check(decoded);
|
|
|
|
assert(encoded_string == TrimString(encoded_string));
|
|
|
|
assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
|
|
|
|
}
|
|
|
|
|
2022-04-04 13:52:06 -04:00
|
|
|
auto result = DecodeBase32(random_encoded_string);
|
|
|
|
if (result) {
|
|
|
|
const std::string encoded_string = EncodeBase32(*result);
|
2019-10-23 12:37:59 +00:00
|
|
|
assert(encoded_string == TrimString(encoded_string));
|
|
|
|
assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
|
|
|
|
}
|
|
|
|
|
2022-04-04 13:52:06 -04:00
|
|
|
result = DecodeBase64(random_encoded_string);
|
|
|
|
if (result) {
|
|
|
|
const std::string encoded_string = EncodeBase64(*result);
|
2019-10-23 12:37:59 +00:00
|
|
|
assert(encoded_string == TrimString(encoded_string));
|
|
|
|
assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
|
|
|
|
}
|
2020-03-11 12:05:52 +00:00
|
|
|
|
|
|
|
PartiallySignedTransaction psbt;
|
|
|
|
std::string error;
|
|
|
|
(void)DecodeBase64PSBT(psbt, random_encoded_string, error);
|
2019-10-23 12:37:59 +00:00
|
|
|
}
|