1 //--------------------------------------------------------------------------
2 // Copyright (C) 2017-2021 Cisco and/or its affiliates. All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License Version 2 as published
6 // by the Free Software Foundation.  You may not use, modify or distribute
7 // this program under any other version of the GNU General Public License.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //--------------------------------------------------------------------------
18 
19 // base64_encoder.h author Russ Combs <rucombs@cisco.com>
20 
21 #ifndef BASE64_ENCODER_H
22 #define BASE64_ENCODER_H
23 
24 // this is based on the excellent work by devolve found at
25 // https://sourceforge.net/projects/libb64/.
26 
27 // usage: instantiate, encode+, finish
28 // buf must hold 2*length_in
29 
30 #include <cstdint>
31 #include "main/snort_types.h"
32 
33 namespace snort
34 {
35 class SO_PUBLIC Base64Encoder
36 {
37 public:
Base64Encoder()38     Base64Encoder()
39     { reset(); }
40 
41     unsigned encode(const uint8_t* plain_text, unsigned length, char* buf);
42     unsigned finish(char* buf);
43 
reset()44     void reset()
45     { step = step_A; state = 0; }
46 
47 private:
48     enum Steps { step_A, step_B, step_C };
49     Steps step;
50     uint8_t state;
51 };
52 }
53 #endif
54 
55