/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 | | #include <botan/asn1_print.h> |
9 | | #include <fstream> |
10 | | |
11 | | class ASN1_Parser final : public Botan::ASN1_Formatter |
12 | | { |
13 | | public: |
14 | 2.81k | ASN1_Parser() : Botan::ASN1_Formatter(true, 64) {} |
15 | | |
16 | | protected: |
17 | | std::string format(Botan::ASN1_Tag, Botan::ASN1_Tag, size_t, size_t, |
18 | | const std::string&) const override |
19 | 36.8k | { |
20 | 36.8k | return ""; |
21 | 36.8k | } |
22 | | |
23 | | std::string format_bin(Botan::ASN1_Tag, Botan::ASN1_Tag, |
24 | | const std::vector<uint8_t>&) const override |
25 | 11.5k | { |
26 | 11.5k | return ""; |
27 | 11.5k | } |
28 | | }; |
29 | | |
30 | | void fuzz(const uint8_t in[], size_t len) |
31 | 14.7k | { |
32 | 14.7k | try |
33 | 14.7k | { |
34 | | /* |
35 | | * Here we use an uninitialized ofstream so the fuzzer doesn't spend time |
36 | | * on actual output formatting, no memory is allocated, etc. |
37 | | */ |
38 | 14.7k | std::ofstream out; |
39 | 14.7k | ASN1_Parser printer; |
40 | 14.7k | printer.print_to_stream(out, in, len); |
41 | 14.7k | } |
42 | 11.3k | catch(Botan::Exception& e) { } |
43 | 14.7k | } |