22 std::vector<Key> dummy_keys;
23 std::map<Key, int> dummy_key_idx_map;
24 std::map<CKeyID, Key> dummy_keys_map;
28 unsigned char keydata[32] = {1};
29 for (
size_t i = 0; i < 256; i++) {
32 privkey.
Set(keydata, keydata + 32,
true);
35 dummy_keys.push_back(pubkey);
36 dummy_key_idx_map.emplace(pubkey, i);
37 dummy_keys_map.insert({pubkey.GetID(), pubkey});
47 struct ParserContext {
50 bool KeyCompare(
const Key& a,
const Key& b)
const {
54 std::optional<std::string>
ToString(
const Key& key)
const 56 auto it = TEST_DATA.dummy_key_idx_map.find(key);
57 if (it == TEST_DATA.dummy_key_idx_map.end())
return {};
58 uint8_t idx = it->second;
63 std::optional<Key>
FromString(I first, I last)
const {
64 if (last - first != 2)
return {};
65 auto idx =
ParseHex(std::string(first, last));
66 if (idx.size() != 1)
return {};
67 return TEST_DATA.dummy_keys[idx[0]];
71 std::optional<Key> FromPKBytes(I first, I last)
const {
74 if (!key.IsValid())
return {};
79 std::optional<Key> FromPKHBytes(I first, I last)
const {
80 assert(last - first == 20);
82 std::copy(first, last, keyid.
begin());
83 const auto it = TEST_DATA.dummy_keys_map.find(keyid);
84 if (it == TEST_DATA.dummy_keys_map.end())
return {};
90 struct ScriptParserContext {
94 std::vector<unsigned char> data;
97 bool KeyCompare(
const Key& a,
const Key& b)
const {
98 return a.data < b.data;
101 const std::vector<unsigned char>& ToPKBytes(
const Key& key)
const 107 const std::vector<unsigned char> ToPKHBytes(
const Key& key)
const 109 if (key.is_hash)
return key.data;
110 const auto h =
Hash160(key.data);
111 return {h.begin(), h.end()};
115 std::optional<Key> FromPKBytes(I first, I last)
const 118 key.data.assign(first, last);
124 std::optional<Key> FromPKHBytes(I first, I last)
const 127 key.data.assign(first, last);
131 } SCRIPT_PARSER_CONTEXT;
149 const auto str2 = parsed->ToString(PARSER_CTX);
153 assert(*parsed == *parsed2);
160 const std::optional<CScript> script = ConsumeDeserializable<CScript>(fuzzed_data_provider);
166 assert(ms->ToScript(SCRIPT_PARSER_CONTEXT) == *script);
NodeRef< typename Ctx::Key > FromString(const std::string &str, const Ctx &ctx)
FUZZ_TARGET(miniscript_script)
CPubKey GetPubKey() const
Compute the public key from a private key.
FUZZ_TARGET_INIT(miniscript_string, FuzzInit)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
std::vector< Byte > ParseHex(std::string_view str)
Parse the hex string into bytes (uint8_t or std::byte).
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
An encapsulated public key.
std::string ConsumeRemainingBytesAsString()
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
uint160 Hash160(const T1 &in1)
Compute the 160-bit hash an object.
A reference to a CKey: the Hash160 of its serialized public key.
An encapsulated private key.
A Span is an object that can refer to a contiguous sequence of objects.
NodeRef< typename Ctx::Key > FromScript(const CScript &script, const Ctx &ctx)