Botan  1.11.15
src/lib/codec/base64/base64.h
Go to the documentation of this file.
00001 /*
00002 * Base64 Encoding and Decoding
00003 * (C) 2010 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_BASE64_CODEC_H__
00009 #define BOTAN_BASE64_CODEC_H__
00010 
00011 #include <botan/secmem.h>
00012 #include <string>
00013 
00014 namespace Botan {
00015 
00016 /**
00017 * Perform base64 encoding
00018 * @param output an array of at least input_length*4/3 bytes
00019 * @param input is some binary data
00020 * @param input_length length of input in bytes
00021 * @param input_consumed is an output parameter which says how many
00022 *        bytes of input were actually consumed. If less than
00023 *        input_length, then the range input[consumed:length]
00024 *        should be passed in later along with more input.
00025 * @param final_inputs true iff this is the last input, in which case
00026          padding chars will be applied if needed
00027 * @return number of bytes written to output
00028 */
00029 size_t BOTAN_DLL base64_encode(char output[],
00030                                const byte input[],
00031                                size_t input_length,
00032                                size_t& input_consumed,
00033                                bool final_inputs);
00034 
00035 /**
00036 * Perform base64 encoding
00037 * @param input some input
00038 * @param input_length length of input in bytes
00039 * @return base64adecimal representation of input
00040 */
00041 std::string BOTAN_DLL base64_encode(const byte input[],
00042                                     size_t input_length);
00043 
00044 /**
00045 * Perform base64 encoding
00046 * @param input some input
00047 * @return base64adecimal representation of input
00048 */
00049 template<typename Alloc>
00050 std::string base64_encode(const std::vector<byte, Alloc>& input)
00051    {
00052    return base64_encode(&input[0], input.size());
00053    }
00054 
00055 /**
00056 * Perform base64 decoding
00057 * @param output an array of at least input_length*3/4 bytes
00058 * @param input some base64 input
00059 * @param input_length length of input in bytes
00060 * @param input_consumed is an output parameter which says how many
00061 *        bytes of input were actually consumed. If less than
00062 *        input_length, then the range input[consumed:length]
00063 *        should be passed in later along with more input.
00064 * @param final_inputs true iff this is the last input, in which case
00065          padding is allowed
00066 * @param ignore_ws ignore whitespace on input; if false, throw an
00067                    exception if whitespace is encountered
00068 * @return number of bytes written to output
00069 */
00070 size_t BOTAN_DLL base64_decode(byte output[],
00071                                const char input[],
00072                                size_t input_length,
00073                                size_t& input_consumed,
00074                                bool final_inputs,
00075                                bool ignore_ws = true);
00076 
00077 /**
00078 * Perform base64 decoding
00079 * @param output an array of at least input_length*3/4 bytes
00080 * @param input some base64 input
00081 * @param input_length length of input in bytes
00082 * @param ignore_ws ignore whitespace on input; if false, throw an
00083                    exception if whitespace is encountered
00084 * @return number of bytes written to output
00085 */
00086 size_t BOTAN_DLL base64_decode(byte output[],
00087                                const char input[],
00088                                size_t input_length,
00089                                bool ignore_ws = true);
00090 
00091 /**
00092 * Perform base64 decoding
00093 * @param output an array of at least input_length/3*4 bytes
00094 * @param input some base64 input
00095 * @param ignore_ws ignore whitespace on input; if false, throw an
00096                    exception if whitespace is encountered
00097 * @return number of bytes written to output
00098 */
00099 size_t BOTAN_DLL base64_decode(byte output[],
00100                                const std::string& input,
00101                                bool ignore_ws = true);
00102 
00103 /**
00104 * Perform base64 decoding
00105 * @param input some base64 input
00106 * @param input_length the length of input in bytes
00107 * @param ignore_ws ignore whitespace on input; if false, throw an
00108                    exception if whitespace is encountered
00109 * @return decoded base64 output
00110 */
00111 secure_vector<byte> BOTAN_DLL base64_decode(const char input[],
00112                                            size_t input_length,
00113                                            bool ignore_ws = true);
00114 
00115 /**
00116 * Perform base64 decoding
00117 * @param input some base64 input
00118 * @param ignore_ws ignore whitespace on input; if false, throw an
00119                    exception if whitespace is encountered
00120 * @return decoded base64 output
00121 */
00122 secure_vector<byte> BOTAN_DLL base64_decode(const std::string& input,
00123                                            bool ignore_ws = true);
00124 
00125 }
00126 
00127 #endif