fuzz: introduce and use ConsumePrivateKey
helper
#28419
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the course of reviewing BIP324 related PRs I noticed a frequent pattern of creating private keys (
CKey
instances) with data consumed from the fuzz data provider:This PR introduces a corresponding helper
ConsumePrivateKey
in order to deduplicate code. The compressed flag can either be set to a fixed value, or, ifstd::nullopt
is passed (=default), is also consumed from the fuzz data provider via.ConsumeBool()
.Note that this is not a pure refactor, as some of the replaced call-sites previously consumed a random length (
ConsumeRandomLengthByteVector
) instead of a fixed size of 32 bytes for key data. As far as I can see, there is not much value in using a random size, as in all those cases we can only proceed or do something useful with a valid private key, and key data with sizes other than 32 bytes always lead to invalid keys.