Coverage Report

Created: 2022-09-23 06:05

/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.96k
      ASN1_Parser() : Botan::ASN1_Formatter(true, 64) {}
15
16
   protected:
17
      std::string format(Botan::ASN1_Type, Botan::ASN1_Class, size_t, size_t,
18
                         const std::string&) const override
19
34.5k
         {
20
34.5k
         return "";
21
34.5k
         }
22
23
      std::string format_bin(Botan::ASN1_Type, Botan::ASN1_Class,
24
                             const std::vector<uint8_t>&) const override
25
13.3k
         {
26
13.3k
         return "";
27
13.3k
         }
28
29
      std::string format_bn(const Botan::BigInt&) const override
30
1.65k
         {
31
1.65k
         return "";
32
1.65k
         }
33
   };
34
35
void fuzz(const uint8_t in[], size_t len)
36
19.7k
   {
37
19.7k
   try
38
19.7k
      {
39
      /*
40
      * Here we use an uninitialized ofstream so the fuzzer doesn't spend time
41
      * on actual output formatting, no memory is allocated, etc.
42
      */
43
19.7k
      std::ofstream out;
44
19.7k
      ASN1_Parser printer;
45
19.7k
      printer.print_to_stream(out, in, len);
46
19.7k
      }
47
19.7k
   catch(Botan::Exception& e) { }
48
19.7k
   }