8 #include <botan/b64_filt.h>
9 #include <botan/base64.h>
10 #include <botan/charset.h>
11 #include <botan/exceptn.h>
20 line_length(breaks ? length : 0),
21 trailing_newline(t_n && breaks),
32 void Base64_Encoder::encode_and_send(
const byte input[],
size_t length,
37 const size_t proc = std::min(length, in.
size());
40 size_t produced =
base64_encode(reinterpret_cast<char*>(&out[0]), input,
41 proc, consumed, final_inputs);
43 do_output(&out[0], produced);
54 void Base64_Encoder::do_output(
const byte input[],
size_t length)
60 size_t remaining = length, offset = 0;
63 size_t sent = std::min(line_length - out_position, remaining);
64 send(input + offset, sent);
68 if(out_position == line_length)
82 in.
copy(position, input, length);
83 if(position + length >= in.
size())
85 encode_and_send(&in[0], in.
size());
86 input += (in.
size() - position);
87 length -= (in.
size() - position);
88 while(length >= in.
size())
90 encode_and_send(input, in.
size());
94 in.
copy(input, length);
105 encode_and_send(&in[0], position,
true);
107 if(trailing_newline || (out_position && line_length))
110 out_position = position = 0;
117 checking(c), in(64), out(48), position(0)
128 size_t to_copy = std::min<size_t>(length, in.
size() - position);
129 copy_mem(&in[position], input, to_copy);
134 reinterpret_cast<const char*>(&in[0]),
142 if(consumed != position)
144 copy_mem(&in[0], &in[consumed], position - consumed);
145 position = position - consumed;
162 reinterpret_cast<const char*>(&in[0]),
170 const bool not_full_bytes = consumed != position;
175 throw std::invalid_argument(
"Base64_Decoder: Input not full bytes");
Base64_Encoder(bool breaks=false, size_t length=72, bool t_n=false)
size_t base64_decode(byte output[], const char input[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
Base64_Decoder(Decoder_Checking checking=NONE)
void copy(const T in[], size_t n)
void send(const byte in[], size_t length)
void write(const byte input[], size_t length)
void copy_mem(T *out, const T *in, size_t n)
void write(const byte input[], size_t length)
size_t base64_encode(char out[], const byte in[], size_t input_length, size_t &input_consumed, bool final_inputs)