|
Botan
1.11.15
|
#include <buf_filt.h>
Public Member Functions | |
| Buffered_Filter (size_t block_size, size_t final_minimum) | |
| void | end_msg () |
| void | write (const byte in[], size_t length) |
| template<typename Alloc > | |
| void | write (const std::vector< byte, Alloc > &in, size_t length) |
| virtual | ~Buffered_Filter () |
Protected Member Functions | |
| void | buffer_reset () |
| virtual void | buffered_block (const byte input[], size_t length)=0 |
| size_t | buffered_block_size () const |
| virtual void | buffered_final (const byte input[], size_t length)=0 |
| size_t | current_position () const |
Filter mixin that breaks input into blocks, useful for cipher modes
Definition at line 19 of file buf_filt.h.
| Botan::Buffered_Filter::Buffered_Filter | ( | size_t | block_size, |
| size_t | final_minimum | ||
| ) |
Initialize a Buffered_Filter
| 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.
:
main_block_mod(b), final_minimum(f)
{
if(main_block_mod == 0)
throw std::invalid_argument("main_block_mod == 0");
if(final_minimum > main_block_mod)
throw std::invalid_argument("final_minimum > main_block_mod");
buffer.resize(2 * main_block_mod);
buffer_pos = 0;
}
| virtual Botan::Buffered_Filter::~Buffered_Filter | ( | ) | [inline, virtual] |
Definition at line 52 of file buf_filt.h.
{}
| void Botan::Buffered_Filter::buffer_reset | ( | ) | [inline, protected] |
| virtual void Botan::Buffered_Filter::buffered_block | ( | const byte | input[], |
| size_t | length | ||
| ) | [protected, pure virtual] |
| size_t Botan::Buffered_Filter::buffered_block_size | ( | ) | const [inline, protected] |
| virtual void Botan::Buffered_Filter::buffered_final | ( | const byte | input[], |
| size_t | length | ||
| ) | [protected, pure virtual] |
The final block, implemented by subclasses
| 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 [inline, protected] |
Definition at line 78 of file buf_filt.h.
{ return 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().
{
if(buffer_pos < final_minimum)
throw std::runtime_error("Buffered filter end_msg without enough input");
size_t spare_blocks = (buffer_pos - final_minimum) / main_block_mod;
if(spare_blocks)
{
size_t spare_bytes = main_block_mod * spare_blocks;
buffered_block(&buffer[0], spare_bytes);
buffered_final(&buffer[spare_bytes], buffer_pos - spare_bytes);
}
else
{
buffered_final(&buffer[0], buffer_pos);
}
buffer_pos = 0;
}
| void Botan::Buffered_Filter::write | ( | const byte | in[], |
| size_t | length | ||
| ) |
Write bytes into the buffered filter, which will them emit them in calls to buffered_block in the subclass
| 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().
{
if(!input_size)
return;
if(buffer_pos + input_size >= main_block_mod + final_minimum)
{
size_t to_copy = std::min<size_t>(buffer.size() - buffer_pos, input_size);
copy_mem(&buffer[buffer_pos], input, to_copy);
buffer_pos += to_copy;
input += to_copy;
input_size -= to_copy;
size_t total_to_consume =
round_down(std::min(buffer_pos,
buffer_pos + input_size - final_minimum),
main_block_mod);
buffered_block(&buffer[0], total_to_consume);
buffer_pos -= total_to_consume;
copy_mem(&buffer[0], &buffer[0] + total_to_consume, buffer_pos);
}
if(input_size >= final_minimum)
{
size_t full_blocks = (input_size - final_minimum) / main_block_mod;
size_t to_copy = full_blocks * main_block_mod;
if(to_copy)
{
buffered_block(input, to_copy);
input += to_copy;
input_size -= to_copy;
}
}
copy_mem(&buffer[buffer_pos], input, input_size);
buffer_pos += input_size;
}
| void Botan::Buffered_Filter::write | ( | const std::vector< byte, Alloc > & | in, |
| size_t | length | ||
| ) | [inline] |
Definition at line 31 of file buf_filt.h.
{
write(&in[0], length);
}
1.7.6.1