8#include <botan/filters.h>
10#include <botan/exceptn.h>
12#include <botan/mem_ops.h>
27 m_out.resize(2 * m_in.size());
35 m_out.resize(2 * m_in.size());
41void Hex_Encoder::encode_and_send(
const uint8_t block[],
size_t length) {
44 if(m_line_length == 0) {
45 send(m_out, 2 * length);
47 size_t remaining = 2 * length;
49 while(remaining > 0) {
50 size_t sent = std::min(m_line_length - m_counter, remaining);
51 send(&m_out[offset], sent);
55 if(m_counter == m_line_length) {
67 const size_t initial_fill = std::min(m_in.size() - m_position, length);
68 copy_mem(&m_in[m_position], input, initial_fill);
70 if(m_position + length >= m_in.size()) {
71 encode_and_send(m_in.data(), m_in.size());
72 input += (m_in.size() - m_position);
73 length -= (m_in.size() - m_position);
74 while(length >= m_in.size()) {
75 encode_and_send(input, m_in.size());
77 length -= m_in.size();
79 copy_mem(m_in.data(), input, length);
89 encode_and_send(m_in.data(), m_position);
90 if(m_counter > 0 && m_line_length > 0) {
93 m_counter = m_position = 0;
101 m_out.resize(m_in.size() / 2);
109 size_t to_copy = std::min<size_t>(length, m_in.size() - m_position);
110 copy_mem(&m_in[m_position], input, to_copy);
111 m_position += to_copy;
117 send(m_out, written);
119 if(consumed != m_position) {
120 copy_mem(m_in.data(), m_in.data() + consumed, m_position - consumed);
121 m_position = m_position - consumed;
139 send(m_out, written);
141 const bool not_full_bytes = consumed != m_position;
virtual void send(const uint8_t in[], size_t length)
Hex_Decoder(Decoder_Checking checking=NONE)
void write(const uint8_t input[], size_t length) override
void write(const uint8_t in[], size_t length) override
Hex_Encoder(Case the_case)
constexpr void copy_mem(T *out, const T *in, size_t n)
const size_t HEX_CODEC_BUFFER_SIZE
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
size_t hex_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
const char * cast_uint8_ptr_to_char(const uint8_t *b)