8#include <botan/filters.h>
10#include <botan/exceptn.h>
26 m_out.resize(2 * m_in.size());
27 m_counter = m_position = 0;
35 m_out.resize(2 * m_in.size());
36 m_counter = m_position = 0;
42void Hex_Encoder::encode_and_send(
const uint8_t block[],
size_t length) {
45 if(m_line_length == 0) {
46 send(m_out, 2 * length);
48 size_t remaining = 2 * length, offset = 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 && m_line_length) {
93 m_counter = m_position = 0;
101 m_out.resize(m_in.size() / 2);
110 size_t to_copy = std::min<size_t>(length, m_in.size() - m_position);
111 copy_mem(&m_in[m_position], input, to_copy);
112 m_position += to_copy;
118 send(m_out, written);
120 if(consumed != m_position) {
121 copy_mem(m_in.data(), m_in.data() + consumed, m_position - consumed);
122 m_position = m_position - consumed;
140 send(m_out, written);
142 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[], size_t) override
void write(const uint8_t in[], size_t length) override
Hex_Encoder(Case the_case)
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)
constexpr void copy_mem(T *out, const T *in, size_t n)