Line data Source code
1 : // Copyright (c) 2019-2022 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 <test/fuzz/fuzz.h> 6 : 7 : #include <base58.h> 8 : #include <psbt.h> 9 : #include <util/strencodings.h> 10 : #include <util/string.h> 11 : 12 : #include <cassert> 13 : #include <cstdint> 14 : #include <string> 15 : #include <vector> 16 : 17 6 : FUZZ_TARGET(base_encode_decode) 18 2 : { 19 0 : const std::string random_encoded_string(buffer.begin(), buffer.end()); 20 : 21 0 : std::vector<unsigned char> decoded; 22 0 : if (DecodeBase58(random_encoded_string, decoded, 100)) { 23 0 : const std::string encoded_string = EncodeBase58(decoded); 24 0 : assert(encoded_string == TrimStringView(encoded_string)); 25 2 : assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string))); 26 0 : } 27 2 : 28 0 : if (DecodeBase58Check(random_encoded_string, decoded, 100)) { 29 0 : const std::string encoded_string = EncodeBase58Check(decoded); 30 0 : assert(encoded_string == TrimString(encoded_string)); 31 0 : assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string))); 32 0 : } 33 : 34 0 : auto result = DecodeBase32(random_encoded_string); 35 0 : if (result) { 36 0 : const std::string encoded_string = EncodeBase32(*result); 37 0 : assert(encoded_string == TrimStringView(encoded_string)); 38 0 : assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string))); 39 0 : } 40 : 41 0 : result = DecodeBase64(random_encoded_string); 42 0 : if (result) { 43 0 : const std::string encoded_string = EncodeBase64(*result); 44 0 : assert(encoded_string == TrimString(encoded_string)); 45 0 : assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string))); 46 0 : } 47 : 48 0 : PartiallySignedTransaction psbt; 49 0 : std::string error; 50 0 : (void)DecodeBase64PSBT(psbt, random_encoded_string, error); 51 0 : }