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:
2 files changed
+7
-7
No files matched your search
@@ -74,7 +74,7 @@ std::optional<std::string> MockedDescriptorConverter::GetDescriptor(std::string_
|
|||||||
return desc;
|
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};
|
auto depth{0};
|
||||||
for (const auto& ch: buff) {
|
for (const auto& ch: buff) {
|
||||||
@@ -88,7 +88,7 @@ bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth)
|
|||||||
return false;
|
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.
|
// We use a stack because there may be many nested sub-frags.
|
||||||
std::stack<int> counts;
|
std::stack<int> counts;
|
||||||
@@ -112,7 +112,7 @@ bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs, const siz
|
|||||||
return false;
|
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
|
// 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.
|
// 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
|
* 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.
|
* 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.
|
//! Default maximum number of sub-fragments.
|
||||||
constexpr int MAX_SUBS{1'000};
|
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
|
* Whether the buffer, if it represents a valid descriptor, contains a fragment with more
|
||||||
* sub-fragments than the given maximum.
|
* sub-fragments than the given maximum.
|
||||||
*/
|
*/
|
||||||
bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs = MAX_SUBS,
|
bool HasTooManySubFrag(std::span<const uint8_t> buff, int max_subs = MAX_SUBS,
|
||||||
const size_t max_nested_subs = MAX_NESTED_SUBS);
|
size_t max_nested_subs = MAX_NESTED_SUBS);
|
||||||
|
|
||||||
//! Default maximum number of wrappers per fragment.
|
//! Default maximum number of wrappers per fragment.
|
||||||
constexpr int MAX_WRAPPERS{100};
|
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
|
* Whether the buffer, if it represents a valid descriptor, contains a fragment with more
|
||||||
* wrappers than the given maximum.
|
* 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
|
#endif // BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H
|
||||||
Reference in new issue
Block a user