Botan  2.6.0
Crypto and TLS for C++11
base64.h
Go to the documentation of this file.
1 /*
2 * Base64 Encoding and Decoding
3 * (C) 2010 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_BASE64_CODEC_H_
9 #define BOTAN_BASE64_CODEC_H_
10 
11 #include <botan/secmem.h>
12 #include <string>
13 
14 namespace Botan {
15 
16 /**
17 * Perform base64 encoding
18 * @param output an array of at least base64_encode_max_output bytes
19 * @param input is some binary data
20 * @param input_length length of input in bytes
21 * @param input_consumed is an output parameter which says how many
22 * bytes of input were actually consumed. If less than
23 * input_length, then the range input[consumed:length]
24 * should be passed in later along with more input.
25 * @param final_inputs true iff this is the last input, in which case
26  padding chars will be applied if needed
27 * @return number of bytes written to output
28 */
29 size_t BOTAN_PUBLIC_API(2,0) base64_encode(char output[],
30  const uint8_t input[],
31  size_t input_length,
32  size_t& input_consumed,
33  bool final_inputs);
34 
35 /**
36 * Perform base64 encoding
37 * @param input some input
38 * @param input_length length of input in bytes
39 * @return base64adecimal representation of input
40 */
41 std::string BOTAN_PUBLIC_API(2,0) base64_encode(const uint8_t input[],
42  size_t input_length);
43 
44 /**
45 * Perform base64 encoding
46 * @param input some input
47 * @return base64adecimal representation of input
48 */
49 template<typename Alloc>
50 std::string base64_encode(const std::vector<uint8_t, Alloc>& input)
51  {
52  return base64_encode(input.data(), input.size());
53  }
54 
55 /**
56 * Perform base64 decoding
57 * @param output an array of at least base64_decode_max_output bytes
58 * @param input some base64 input
59 * @param input_length length of input in bytes
60 * @param input_consumed is an output parameter which says how many
61 * bytes of input were actually consumed. If less than
62 * input_length, then the range input[consumed:length]
63 * should be passed in later along with more input.
64 * @param final_inputs true iff this is the last input, in which case
65  padding is allowed
66 * @param ignore_ws ignore whitespace on input; if false, throw an
67  exception if whitespace is encountered
68 * @return number of bytes written to output
69 */
70 size_t BOTAN_PUBLIC_API(2,0) base64_decode(uint8_t output[],
71  const char input[],
72  size_t input_length,
73  size_t& input_consumed,
74  bool final_inputs,
75  bool ignore_ws = true);
76 
77 /**
78 * Perform base64 decoding
79 * @param output an array of at least base64_decode_max_output bytes
80 * @param input some base64 input
81 * @param input_length length of input in bytes
82 * @param ignore_ws ignore whitespace on input; if false, throw an
83  exception if whitespace is encountered
84 * @return number of bytes written to output
85 */
86 size_t BOTAN_PUBLIC_API(2,0) base64_decode(uint8_t output[],
87  const char input[],
88  size_t input_length,
89  bool ignore_ws = true);
90 
91 /**
92 * Perform base64 decoding
93 * @param output an array of at least base64_decode_max_output bytes
94 * @param input some base64 input
95 * @param ignore_ws ignore whitespace on input; if false, throw an
96  exception if whitespace is encountered
97 * @return number of bytes written to output
98 */
99 size_t BOTAN_PUBLIC_API(2,0) base64_decode(uint8_t output[],
100  const std::string& input,
101  bool ignore_ws = true);
102 
103 /**
104 * Perform base64 decoding
105 * @param input some base64 input
106 * @param input_length the length of input in bytes
107 * @param ignore_ws ignore whitespace on input; if false, throw an
108  exception if whitespace is encountered
109 * @return decoded base64 output
110 */
111 secure_vector<uint8_t> BOTAN_PUBLIC_API(2,0) base64_decode(const char input[],
112  size_t input_length,
113  bool ignore_ws = true);
114 
115 /**
116 * Perform base64 decoding
117 * @param input some base64 input
118 * @param ignore_ws ignore whitespace on input; if false, throw an
119  exception if whitespace is encountered
120 * @return decoded base64 output
121 */
122 secure_vector<uint8_t> BOTAN_PUBLIC_API(2,0) base64_decode(const std::string& input,
123  bool ignore_ws = true);
124 
125 /**
126 * Calculate the size of output buffer for base64_encode
127 * @param input_length the length of input in bytes
128 * @return the size of output buffer in bytes
129 */
130 size_t BOTAN_PUBLIC_API(2,1) base64_encode_max_output(size_t input_length);
131 
132 /**
133 * Calculate the size of output buffer for base64_decode
134 * @param input_length the length of input in bytes
135 * @return the size of output buffer in bytes
136 */
137 size_t BOTAN_PUBLIC_API(2,1) base64_decode_max_output(size_t input_length);
138 
139 }
140 
141 #endif
size_t base64_decode_max_output(size_t input_length)
Definition: base64.cpp:256
size_t base64_encode_max_output(size_t input_length)
Definition: base64.cpp:251
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: bigint.h:719
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition: base64.cpp:35
size_t base64_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
Definition: base64.cpp:100
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88