#include <filters.h>
|
| Buffered_Filter (size_t block_size, size_t final_minimum) |
|
void | end_msg () |
|
void | write (const uint8_t in[], size_t length) |
|
template<typename Alloc > |
void | write (const std::vector< uint8_t, Alloc > &in, size_t length) |
|
virtual | ~Buffered_Filter ()=default |
|
Filter mixin that breaks input into blocks, useful for cipher modes
Definition at line 40 of file filters.h.
Botan::Buffered_Filter::Buffered_Filter |
( |
size_t |
block_size, |
|
|
size_t |
final_minimum |
|
) |
| |
Initialize a Buffered_Filter
- Parameters
-
block_size | the function buffered_block will be called with inputs which are a multiple of this size |
final_minimum | the function buffered_final will be called with at least this many bytes. |
Definition at line 18 of file buf_filt.cpp.
19 m_main_block_mod(b), m_final_minimum(f)
21 if(m_main_block_mod == 0)
22 throw Invalid_Argument(
"m_main_block_mod == 0");
24 if(m_final_minimum > m_main_block_mod)
25 throw Invalid_Argument(
"m_final_minimum > m_main_block_mod");
27 m_buffer.resize(2 * m_main_block_mod);
virtual Botan::Buffered_Filter::~Buffered_Filter |
( |
| ) |
|
|
virtualdefault |
void Botan::Buffered_Filter::buffer_reset |
( |
| ) |
|
|
inlineprotected |
Reset the buffer position
Definition at line 104 of file filters.h.
104 { m_buffer_pos = 0; }
virtual void Botan::Buffered_Filter::buffered_block |
( |
const uint8_t |
input[], |
|
|
size_t |
length |
|
) |
| |
|
protectedpure virtual |
The block processor, implemented by subclasses
- Parameters
-
input | some input bytes |
length | the size of input, guaranteed to be a multiple of block_size |
Referenced by end_msg(), and write().
size_t Botan::Buffered_Filter::buffered_block_size |
( |
| ) |
const |
|
inlineprotected |
- Returns
- block size of inputs
Definition at line 94 of file filters.h.
94 {
return m_main_block_mod; }
virtual void Botan::Buffered_Filter::buffered_final |
( |
const uint8_t |
input[], |
|
|
size_t |
length |
|
) |
| |
|
protectedpure virtual |
The final block, implemented by subclasses
- Parameters
-
input | some input bytes |
length | the size of input, guaranteed to be at least final_minimum bytes |
Referenced by end_msg().
size_t Botan::Buffered_Filter::current_position |
( |
| ) |
const |
|
inlineprotected |
- Returns
- current position in the buffer
Definition at line 99 of file filters.h.
99 {
return m_buffer_pos; }
void Botan::Buffered_Filter::end_msg |
( |
| ) |
|
Finish a message, emitting to buffered_block and buffered_final Will throw an exception if less than final_minimum bytes were written into the filter.
Definition at line 82 of file buf_filt.cpp.
References buffered_block(), and buffered_final().
84 if(m_buffer_pos < m_final_minimum)
85 throw Invalid_State(
"Buffered filter end_msg without enough input");
87 size_t spare_blocks = (m_buffer_pos - m_final_minimum) / m_main_block_mod;
91 size_t spare_bytes = m_main_block_mod * spare_blocks;
93 buffered_final(&m_buffer[spare_bytes], m_buffer_pos - spare_bytes);
virtual void buffered_block(const uint8_t input[], size_t length)=0
virtual void buffered_final(const uint8_t input[], size_t length)=0
void Botan::Buffered_Filter::write |
( |
const uint8_t |
in[], |
|
|
size_t |
length |
|
) |
| |
Write bytes into the buffered filter, which will them emit them in calls to buffered_block in the subclass
- Parameters
-
in | the input bytes |
length | of in in bytes |
Definition at line 34 of file buf_filt.cpp.
References buffered_block(), Botan::copy_mem(), and Botan::round_down().
39 if(m_buffer_pos + input_size >= m_main_block_mod + m_final_minimum)
41 size_t to_copy = std::min<size_t>(m_buffer.size() - m_buffer_pos, input_size);
43 copy_mem(&m_buffer[m_buffer_pos], input, to_copy);
44 m_buffer_pos += to_copy;
47 input_size -= to_copy;
49 size_t total_to_consume =
51 m_buffer_pos + input_size - m_final_minimum),
56 m_buffer_pos -= total_to_consume;
58 copy_mem(m_buffer.data(), m_buffer.data() + total_to_consume, m_buffer_pos);
61 if(input_size >= m_final_minimum)
63 size_t full_blocks = (input_size - m_final_minimum) / m_main_block_mod;
64 size_t to_copy = full_blocks * m_main_block_mod;
71 input_size -= to_copy;
75 copy_mem(&m_buffer[m_buffer_pos], input, input_size);
76 m_buffer_pos += input_size;
virtual void buffered_block(const uint8_t input[], size_t length)=0
void copy_mem(T *out, const T *in, size_t n)
constexpr T round_down(T n, T align_to)
template<typename Alloc >
void Botan::Buffered_Filter::write |
( |
const std::vector< uint8_t, Alloc > & |
in, |
|
|
size_t |
length |
|
) |
| |
|
inline |
Definition at line 52 of file filters.h.
54 write(in.data(), length);
void write(const uint8_t in[], size_t length)
The documentation for this class was generated from the following files: