6
6
7
7
#include < base58.h>
8
8
#include < psbt.h>
9
+ #include < span.h>
9
10
#include < test/fuzz/FuzzedDataProvider.h>
10
11
#include < util/strencodings.h>
11
12
#include < util/string.h>
@@ -19,42 +20,40 @@ using util::TrimStringView;
19
20
20
21
FUZZ_TARGET (base58_encode_decode)
21
22
{
22
- FuzzedDataProvider provider ( buffer.data (), buffer.size ()) ;
23
- const std::string random_string{provider.ConsumeRandomLengthString (1000 )};
24
- const int max_ret_len{provider.ConsumeIntegralInRange <int >(-1 , 1000 )};
23
+ FuzzedDataProvider provider{ buffer.data (), buffer.size ()} ;
24
+ const auto random_string{provider.ConsumeRandomLengthString (100 )};
25
+ const int max_ret_len{provider.ConsumeIntegralInRange <int >(-1 , 100 )};
25
26
26
27
// Decode/Encode roundtrip
27
- std::vector<unsigned char > decoded;
28
- if (DecodeBase58 (random_string, decoded, max_ret_len)) {
28
+ if (std::vector<unsigned char > decoded; DecodeBase58 (random_string, decoded, max_ret_len)) {
29
29
const auto encoded_string{EncodeBase58 (decoded)};
30
30
assert (encoded_string == TrimStringView (random_string));
31
- assert (encoded_string .empty () || !DecodeBase58 (encoded_string, decoded, provider.ConsumeIntegralInRange <int >(0 , decoded.size () - 1 )));
31
+ assert (decoded .empty () || !DecodeBase58 (encoded_string, decoded, provider.ConsumeIntegralInRange <int >(0 , decoded.size () - 1 )));
32
32
}
33
33
// Encode/Decode roundtrip
34
- const auto encoded{EncodeBase58 (buffer )};
34
+ const auto encoded{EncodeBase58 (MakeUCharSpan (random_string) )};
35
35
std::vector<unsigned char > roundtrip_decoded;
36
- assert (DecodeBase58 (encoded, roundtrip_decoded, buffer .size ())
37
- && std::ranges::equal (roundtrip_decoded, buffer ));
36
+ assert (DecodeBase58 (encoded, roundtrip_decoded, random_string .size ())
37
+ && std::ranges::equal (roundtrip_decoded, MakeUCharSpan (random_string) ));
38
38
}
39
39
40
40
FUZZ_TARGET (base58check_encode_decode)
41
41
{
42
- FuzzedDataProvider provider ( buffer.data (), buffer.size ()) ;
43
- const std::string random_string{provider.ConsumeRandomLengthString (1000 )};
44
- const int max_ret_len{provider.ConsumeIntegralInRange <int >(-1 , 1000 )};
42
+ FuzzedDataProvider provider{ buffer.data (), buffer.size ()} ;
43
+ const auto random_string{provider.ConsumeRandomLengthString (100 )};
44
+ const int max_ret_len{provider.ConsumeIntegralInRange <int >(-1 , 100 )};
45
45
46
46
// Decode/Encode roundtrip
47
- std::vector<unsigned char > decoded;
48
- if (DecodeBase58Check (random_string, decoded, max_ret_len)) {
47
+ if (std::vector<unsigned char > decoded; DecodeBase58Check (random_string, decoded, max_ret_len)) {
49
48
const auto encoded_string{EncodeBase58Check (decoded)};
50
49
assert (encoded_string == TrimStringView (random_string));
51
- assert (encoded_string .empty () || !DecodeBase58Check (encoded_string, decoded, provider.ConsumeIntegralInRange <int >(0 , decoded.size () - 1 )));
50
+ assert (decoded .empty () || !DecodeBase58Check (encoded_string, decoded, provider.ConsumeIntegralInRange <int >(0 , decoded.size () - 1 )));
52
51
}
53
52
// Encode/Decode roundtrip
54
- const auto encoded{EncodeBase58Check (buffer )};
53
+ const auto encoded{EncodeBase58Check (MakeUCharSpan (random_string) )};
55
54
std::vector<unsigned char > roundtrip_decoded;
56
- assert (DecodeBase58Check (encoded, roundtrip_decoded, buffer .size ())
57
- && std::ranges::equal (roundtrip_decoded, buffer ));
55
+ assert (DecodeBase58Check (encoded, roundtrip_decoded, random_string .size ())
56
+ && std::ranges::equal (roundtrip_decoded, MakeUCharSpan (random_string) ));
58
57
}
59
58
60
59
FUZZ_TARGET (base32_encode_decode)
0 commit comments