mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
fuzz: [refactor] Use std::span over FuzzBufferType in descriptor utils
They are exactly the same, but the descriptor utils should not prescribe to use the FuzzBufferType. Using a dedicated type for them clarifies that the utils are not tied to FuzzBufferType. Also, while touching the lines, use `const` only where it is meaningful.
This commit is contained in:
@@ -74,7 +74,7 @@ std::optional<std::string> MockedDescriptorConverter::GetDescriptor(std::string_
|
||||
return desc;
|
||||
}
|
||||
|
||||
bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth)
|
||||
bool HasDeepDerivPath(std::span<const uint8_t> buff, const int max_depth)
|
||||
{
|
||||
auto depth{0};
|
||||
for (const auto& ch: buff) {
|
||||
@@ -88,7 +88,7 @@ bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs, const size_t max_nested_subs)
|
||||
bool HasTooManySubFrag(std::span<const uint8_t> buff, const int max_subs, const size_t max_nested_subs)
|
||||
{
|
||||
// We use a stack because there may be many nested sub-frags.
|
||||
std::stack<int> counts;
|
||||
@@ -112,7 +112,7 @@ bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs, const siz
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HasTooManyWrappers(const FuzzBufferType& buff, const int max_wrappers)
|
||||
bool HasTooManyWrappers(std::span<const uint8_t> buff, const int max_wrappers)
|
||||
{
|
||||
// The number of nested wrappers. Nested wrappers are always characters which follow each other so we don't have to
|
||||
// use a stack as we do above when counting the number of sub-fragments.
|
||||
|
||||
@@ -53,7 +53,7 @@ constexpr int MAX_DEPTH{2};
|
||||
* Whether the buffer, if it represents a valid descriptor, contains a derivation path deeper than
|
||||
* a given maximum depth. Note this may also be hit for deriv paths in origins.
|
||||
*/
|
||||
bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth = MAX_DEPTH);
|
||||
bool HasDeepDerivPath(std::span<const uint8_t> buff, int max_depth = MAX_DEPTH);
|
||||
|
||||
//! Default maximum number of sub-fragments.
|
||||
constexpr int MAX_SUBS{1'000};
|
||||
@@ -64,8 +64,8 @@ constexpr size_t MAX_NESTED_SUBS{10'000};
|
||||
* Whether the buffer, if it represents a valid descriptor, contains a fragment with more
|
||||
* sub-fragments than the given maximum.
|
||||
*/
|
||||
bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs = MAX_SUBS,
|
||||
const size_t max_nested_subs = MAX_NESTED_SUBS);
|
||||
bool HasTooManySubFrag(std::span<const uint8_t> buff, int max_subs = MAX_SUBS,
|
||||
size_t max_nested_subs = MAX_NESTED_SUBS);
|
||||
|
||||
//! Default maximum number of wrappers per fragment.
|
||||
constexpr int MAX_WRAPPERS{100};
|
||||
@@ -74,6 +74,6 @@ constexpr int MAX_WRAPPERS{100};
|
||||
* Whether the buffer, if it represents a valid descriptor, contains a fragment with more
|
||||
* wrappers than the given maximum.
|
||||
*/
|
||||
bool HasTooManyWrappers(const FuzzBufferType& buff, const int max_wrappers = MAX_WRAPPERS);
|
||||
bool HasTooManyWrappers(std::span<const uint8_t> buff, int max_wrappers = MAX_WRAPPERS);
|
||||
|
||||
#endif // BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H
|
||||
|
||||
Reference in New Issue
Block a user