|
| 1 | +// Copyright (c) 2019 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 <util/string.h> |
| 9 | +#include <util/strencodings.h> |
| 10 | + |
| 11 | +#include <cassert> |
| 12 | +#include <cstdint> |
| 13 | +#include <string> |
| 14 | +#include <vector> |
| 15 | + |
| 16 | +void test_one_input(const std::vector<uint8_t>& buffer) |
| 17 | +{ |
| 18 | + const std::string random_encoded_string(buffer.begin(), buffer.end()); |
| 19 | + |
| 20 | + std::vector<unsigned char> decoded; |
| 21 | + if (DecodeBase58(random_encoded_string, decoded, 100)) { |
| 22 | + const std::string encoded_string = EncodeBase58(decoded); |
| 23 | + assert(encoded_string == TrimString(encoded_string)); |
| 24 | + assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string))); |
| 25 | + } |
| 26 | + |
| 27 | + if (DecodeBase58Check(random_encoded_string, decoded, 100)) { |
| 28 | + const std::string encoded_string = EncodeBase58Check(decoded); |
| 29 | + assert(encoded_string == TrimString(encoded_string)); |
| 30 | + assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string))); |
| 31 | + } |
| 32 | + |
| 33 | + bool pf_invalid; |
| 34 | + std::string decoded_string = DecodeBase32(random_encoded_string, &pf_invalid); |
| 35 | + if (!pf_invalid) { |
| 36 | + const std::string encoded_string = EncodeBase32(decoded_string); |
| 37 | + assert(encoded_string == TrimString(encoded_string)); |
| 38 | + assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string))); |
| 39 | + } |
| 40 | + |
| 41 | + decoded_string = DecodeBase64(random_encoded_string, &pf_invalid); |
| 42 | + if (!pf_invalid) { |
| 43 | + const std::string encoded_string = EncodeBase64(decoded_string); |
| 44 | + assert(encoded_string == TrimString(encoded_string)); |
| 45 | + assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string))); |
| 46 | + } |
| 47 | +} |
0 commit comments