/src/botan/src/fuzzer/asn1.cpp
Line | Count | Source |
1 | | /* |
2 | | * (C) 2016,2017 Jack Lloyd |
3 | | * |
4 | | * Botan is released under the Simplified BSD License (see license.txt) |
5 | | */ |
6 | | |
7 | | #include "fuzzers.h" |
8 | | |
9 | | #include <botan/asn1_print.h> |
10 | | #include <fstream> |
11 | | |
12 | | class ASN1_Parser final : public Botan::ASN1_Formatter { |
13 | | public: |
14 | 2.97k | ASN1_Parser() : Botan::ASN1_Formatter(true, 64) {} |
15 | | |
16 | | protected: |
17 | 36.6k | std::string format(Botan::ASN1_Type, Botan::ASN1_Class, size_t, size_t, std::string_view) const override { |
18 | 36.6k | return ""; |
19 | 36.6k | } |
20 | | |
21 | 14.0k | std::string format_bin(Botan::ASN1_Type, Botan::ASN1_Class, const std::vector<uint8_t>&) const override { |
22 | 14.0k | return ""; |
23 | 14.0k | } |
24 | | |
25 | 1.75k | std::string format_bn(const Botan::BigInt&) const override { return ""; } |
26 | | }; |
27 | | |
28 | 28.7k | void fuzz(std::span<const uint8_t> in) { |
29 | 28.7k | try { |
30 | | /* |
31 | | * Here we use an uninitialized ofstream so the fuzzer doesn't spend time |
32 | | * on actual output formatting, no memory is allocated, etc. |
33 | | */ |
34 | 28.7k | std::ofstream out; |
35 | 28.7k | ASN1_Parser printer; |
36 | 28.7k | printer.print_to_stream(out, in.data(), in.size()); |
37 | 28.7k | } catch(Botan::Exception& e) {} |
38 | 28.7k | } |