/src/crow/tests/fuzz/b64_fuzzer.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | #include <cstdint> |
2 | | #include <fuzzer/FuzzedDataProvider.h> |
3 | | |
4 | | #include "crow.h" |
5 | | |
6 | | class FuzzException : public std::exception |
7 | | { |
8 | | virtual const char* what() const throw() |
9 | 0 | { |
10 | 0 | return "Base64 decoding error!"; |
11 | 0 | } |
12 | | }; |
13 | | |
14 | | extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, const std::size_t size) |
15 | 452 | { |
16 | 452 | FuzzedDataProvider fdp{data, size}; |
17 | | |
18 | 452 | std::string plaintext = fdp.ConsumeRandomLengthString(); |
19 | 452 | std::string encoded = crow::utility::base64encode(plaintext, plaintext.size()); |
20 | 452 | std::string decoded = crow::utility::base64decode(encoded, encoded.size()); |
21 | | |
22 | 452 | if (plaintext != decoded) |
23 | 0 | { |
24 | 0 | throw FuzzException(); |
25 | 0 | } |
26 | 452 | return 0; |
27 | 452 | } |