8#include <botan/filters.h>
10#include <botan/base64.h>
11#include <botan/exceptn.h>
20 m_line_length(line_breaks ? line_length : 0),
21 m_trailing_newline(trailing_newline && line_breaks),
30void Base64_Encoder::encode_and_send(
const uint8_t input[],
size_t length,
bool final_inputs) {
32 const size_t proc = std::min(length, m_in.size());
37 do_output(m_out.data(), produced);
48void Base64_Encoder::do_output(
const uint8_t input[],
size_t length) {
49 if(m_line_length == 0) {
52 size_t remaining = length, offset = 0;
54 size_t sent = std::min(m_line_length - m_out_position, remaining);
55 send(input + offset, sent);
56 m_out_position += sent;
59 if(m_out_position == m_line_length) {
71 const size_t initial_fill = std::min(m_in.size() - m_position, length);
72 copy_mem(&m_in[m_position], input, initial_fill);
74 if(m_position + length >= m_in.size()) {
75 encode_and_send(m_in.data(), m_in.size());
76 input += (m_in.size() - m_position);
77 length -= (m_in.size() - m_position);
78 while(length >= m_in.size()) {
79 encode_and_send(input, m_in.size());
81 length -= m_in.size();
83 copy_mem(m_in.data(), input, length);
93 encode_and_send(m_in.data(), m_position,
true);
95 if(m_trailing_newline || (m_out_position && m_line_length)) {
99 m_out_position = m_position = 0;
112 size_t to_copy = std::min<size_t>(length, m_in.size() - m_position);
114 m_in.resize(m_in.size() * 2);
115 m_out.resize(m_out.size() * 2);
117 copy_mem(&m_in[m_position], input, to_copy);
118 m_position += to_copy;
124 send(m_out, written);
126 if(consumed != m_position) {
127 copy_mem(m_in.data(), m_in.data() + consumed, m_position - consumed);
128 m_position = m_position - consumed;
146 send(m_out, written);
148 const bool not_full_bytes = consumed != m_position;
Base64_Decoder(Decoder_Checking checking=NONE)
void write(const uint8_t input[], size_t length) override
void write(const uint8_t input[], size_t length) override
Base64_Encoder(bool line_breaks=false, size_t line_length=72, bool trailing_newline=false)
virtual void send(const uint8_t in[], size_t length)
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
size_t base64_decode(uint8_t out[], const char in[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
const char * cast_uint8_ptr_to_char(const uint8_t *b)
constexpr void copy_mem(T *out, const T *in, size_t n)