Botan
1.11.15
|
00001 /* 00002 * Base64 Encoder/Decoder 00003 * (C) 1999-2010 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_BASE64_FILTER_H__ 00009 #define BOTAN_BASE64_FILTER_H__ 00010 00011 #include <botan/filter.h> 00012 00013 namespace Botan { 00014 00015 /** 00016 * This class represents a Base64 encoder. 00017 */ 00018 class BOTAN_DLL Base64_Encoder : public Filter 00019 { 00020 public: 00021 std::string name() const { return "Base64_Encoder"; } 00022 00023 /** 00024 * Input a part of a message to the encoder. 00025 * @param input the message to input as a byte array 00026 * @param length the length of the byte array input 00027 */ 00028 void write(const byte input[], size_t length); 00029 00030 /** 00031 * Inform the Encoder that the current message shall be closed. 00032 */ 00033 void end_msg(); 00034 00035 /** 00036 * Create a base64 encoder. 00037 * @param breaks whether to use line breaks in the output 00038 * @param length the length of the lines of the output 00039 * @param t_n whether to use a trailing newline 00040 */ 00041 Base64_Encoder(bool breaks = false, size_t length = 72, 00042 bool t_n = false); 00043 private: 00044 void encode_and_send(const byte input[], size_t length, 00045 bool final_inputs = false); 00046 void do_output(const byte output[], size_t length); 00047 00048 const size_t line_length; 00049 const bool trailing_newline; 00050 std::vector<byte> in, out; 00051 size_t position, out_position; 00052 }; 00053 00054 /** 00055 * This object represents a Base64 decoder. 00056 */ 00057 class BOTAN_DLL Base64_Decoder : public Filter 00058 { 00059 public: 00060 std::string name() const { return "Base64_Decoder"; } 00061 00062 /** 00063 * Input a part of a message to the decoder. 00064 * @param input the message to input as a byte array 00065 * @param length the length of the byte array input 00066 */ 00067 void write(const byte input[], size_t length); 00068 00069 /** 00070 * Finish up the current message 00071 */ 00072 void end_msg(); 00073 00074 /** 00075 * Create a base64 decoder. 00076 * @param checking the type of checking that shall be performed by 00077 * the decoder 00078 */ 00079 Base64_Decoder(Decoder_Checking checking = NONE); 00080 private: 00081 const Decoder_Checking checking; 00082 std::vector<byte> in, out; 00083 size_t position; 00084 }; 00085 00086 } 00087 00088 #endif