Botan  2.7.0
Crypto and TLS for C++11
b64_filt.h
Go to the documentation of this file.
1 /*
2 * Base64 Encoder/Decoder
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_BASE64_FILTER_H_
9 #define BOTAN_BASE64_FILTER_H_
10 
11 #include <botan/filter.h>
12 
13 namespace Botan {
14 
15 /**
16 * This class represents a Base64 encoder.
17 */
18 class BOTAN_PUBLIC_API(2,0) Base64_Encoder final : public Filter
19  {
20  public:
21  std::string name() const override { return "Base64_Encoder"; }
22 
23  /**
24  * Input a part of a message to the encoder.
25  * @param input the message to input as a byte array
26  * @param length the length of the byte array input
27  */
28  void write(const uint8_t input[], size_t length) override;
29 
30  /**
31  * Inform the Encoder that the current message shall be closed.
32  */
33  void end_msg() override;
34 
35  /**
36  * Create a base64 encoder.
37  * @param breaks whether to use line breaks in the output
38  * @param length the length of the lines of the output
39  * @param t_n whether to use a trailing newline
40  */
41  Base64_Encoder(bool breaks = false, size_t length = 72,
42  bool t_n = false);
43  private:
44  void encode_and_send(const uint8_t input[], size_t length,
45  bool final_inputs = false);
46  void do_output(const uint8_t output[], size_t length);
47 
48  const size_t m_line_length;
49  const bool m_trailing_newline;
50  std::vector<uint8_t> m_in, m_out;
51  size_t m_position, m_out_position;
52  };
53 
54 /**
55 * This object represents a Base64 decoder.
56 */
57 class BOTAN_PUBLIC_API(2,0) Base64_Decoder final : public Filter
58  {
59  public:
60  std::string name() const override { return "Base64_Decoder"; }
61 
62  /**
63  * Input a part of a message to the decoder.
64  * @param input the message to input as a byte array
65  * @param length the length of the byte array input
66  */
67  void write(const uint8_t input[], size_t length) override;
68 
69  /**
70  * Finish up the current message
71  */
72  void end_msg() override;
73 
74  /**
75  * Create a base64 decoder.
76  * @param checking the type of checking that shall be performed by
77  * the decoder
78  */
79  explicit Base64_Decoder(Decoder_Checking checking = NONE);
80  private:
81  const Decoder_Checking m_checking;
82  std::vector<uint8_t> m_in, m_out;
83  size_t m_position;
84  };
85 
86 }
87 
88 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
std::string name() const override
Definition: b64_filt.h:21
Definition: alg_id.cpp:13
std::string name() const override
Definition: b64_filt.h:60
Decoder_Checking
Definition: filter.h:179