diff options
author | practicalswift <practicalswift@users.noreply.github.com> | 2019-10-23 12:37:59 +0000 |
---|---|---|
committer | practicalswift <practicalswift@users.noreply.github.com> | 2019-12-16 22:50:49 +0000 |
commit | 526dd78bedcebcf170ce13349eb3e9fc7fbf39bb (patch) | |
tree | 57e9ab512c1d2278bf62b11e3ce3ecc653fea338 /src/test/fuzz | |
parent | 32e27129ff26c7cc10321652d5d2678876081983 (diff) | |
download | bitcoin-526dd78bedcebcf170ce13349eb3e9fc7fbf39bb.tar.xz |
tests: Add fuzzing harness for various Base{32,58,64} related functions
Diffstat (limited to 'src/test/fuzz')
-rw-r--r-- | src/test/fuzz/base_encode_decode.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/fuzz/base_encode_decode.cpp b/src/test/fuzz/base_encode_decode.cpp new file mode 100644 index 0000000000..cb0fbdf76f --- /dev/null +++ b/src/test/fuzz/base_encode_decode.cpp @@ -0,0 +1,47 @@ +// Copyright (c) 2019 The Bitcoin Core developers +// 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> +#include <util/string.h> +#include <util/strencodings.h> + +#include <cassert> +#include <cstdint> +#include <string> +#include <vector> + +void test_one_input(const std::vector<uint8_t>& buffer) +{ + 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))); + } + + bool pf_invalid; + std::string decoded_string = DecodeBase32(random_encoded_string, &pf_invalid); + if (!pf_invalid) { + const std::string encoded_string = EncodeBase32(decoded_string); + assert(encoded_string == TrimString(encoded_string)); + assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string))); + } + + decoded_string = DecodeBase64(random_encoded_string, &pf_invalid); + if (!pf_invalid) { + const std::string encoded_string = EncodeBase64(decoded_string); + assert(encoded_string == TrimString(encoded_string)); + assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string))); + } +} |