Files
bitcoin/src/test/fuzz/parse_hd_keypath.cpp
2026-08-07 14:44:17 +02:00

31 lines
1.1 KiB
C++

// Copyright (c) 2009-present 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/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <util/bip32.h>
#include <cassert>
#include <cstdint>
#include <vector>
FUZZ_TARGET(parse_hd_keypath)
{
const std::string keypath_str(buffer.begin(), buffer.end());
std::vector<uint32_t> keypath;
(void)ParseHDKeypath(keypath_str, keypath);
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
const std::vector<uint32_t> random_keypath = ConsumeRandomLengthIntegralVector<uint32_t>(fuzzed_data_provider);
// Roundtrip WriteHDKeypath() and ParseHDKeypath()
for (const bool apostrophe : {false, true}) {
std::vector<uint32_t> roundtrip;
const std::string written{WriteHDKeypath(random_keypath, apostrophe)};
assert(ParseHDKeypath(written, roundtrip));
assert(roundtrip == random_keypath);
}
}