diff options
author | lloyd <[email protected]> | 2009-12-28 00:01:39 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-12-28 00:01:39 +0000 |
commit | 764dfc804acdba454a2f1e6d74c3e93d04af7b57 (patch) | |
tree | a914cd79750738533c469500c6f8eca263c369dd /src/utils | |
parent | f7996c04f84ce483f3423c347a799178ec3f57b0 (diff) |
Kill buf_op - was basically the prototype for Buffering_Filter.
It would be useful in its own right, many other things need to do hashing,
but the tr1 dependency kills it right now. Something to revisit in the C++0x
branch, perhaps?
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/buf_op/buf_op.cpp | 120 | ||||
-rw-r--r-- | src/utils/buf_op/buf_op.h | 45 | ||||
-rw-r--r-- | src/utils/buf_op/info.txt | 11 |
3 files changed, 0 insertions, 176 deletions
diff --git a/src/utils/buf_op/buf_op.cpp b/src/utils/buf_op/buf_op.cpp deleted file mode 100644 index 2b5b943cd..000000000 --- a/src/utils/buf_op/buf_op.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/** -* Buffering Central -* (C) 2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/buf_op.h> -#include <botan/mem_ops.h> -#include <botan/internal/rounding.h> -#include <stdexcept> - -#include <stdio.h> -#include <assert.h> - -namespace Botan { - -namespace { - -const size_t BUFFER_MULTIPLE = 2; - -//static_assert(BUFFER_MULTIPLE >= 2, "BUFFER_MULTIPLE must be >= 2"); - -} - -Buffered_Operation::Buffered_Operation(callback_fn m_fn, - callback_fn f_fn, - size_t buf_mod, - size_t final_minimum) : - main_fn(m_fn), final_fn(f_fn), - final_minimum(final_minimum), main_block_mod(buf_mod), - buffer(BUFFER_MULTIPLE * buf_mod), buffer_pos(0) - { - if(buf_mod == 0) - throw std::invalid_argument("buf_mod == 0"); - - if(final_minimum > buf_mod) - throw std::invalid_argument("final_minimum > buf_mod"); - } - -void Buffered_Operation::reset() - { - clear_mem(&buffer[0], buffer.size()); - buffer_pos = 0; - } - -void Buffered_Operation::write(const byte input[], - size_t input_size) - { - if(!input_size) - return; - - if(buffer_pos + input_size >= main_block_mod + final_minimum) - { - size_t to_copy = std::min(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; - - if(input_size >= final_minimum) - { - size_t to_proc = round_down(buffer_pos, main_block_mod); - main_fn(&buffer[0], to_proc); - - buffer_pos -= to_proc; - - copy_mem(&buffer[0], &buffer[to_proc], buffer_pos); - } - } - - if(input_size >= final_minimum) - { - size_t full_blocks = (input_size - final_minimum) / buffer.size(); - size_t to_copy = full_blocks * buffer.size(); - - if(to_copy) - { - main_fn(input, to_copy); - - input += to_copy; - input_size -= to_copy; - } - } - - assert(input_size + buffer_pos <= buffer.size()); - - copy_mem(&buffer[buffer_pos], input, input_size); - buffer_pos += input_size; - } - -void Buffered_Operation::final() - { - assert(buffer_pos >= final_minimum); - - if(buffer_pos < final_minimum) - throw std::runtime_error("Buffered_Operation::final - not 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; - - assert(spare_bytes <= buffer_pos); - - main_fn(&buffer[0], spare_bytes); - - assert(buffer_pos - spare_bytes >= final_minimum); - final_fn(&buffer[spare_bytes], buffer_pos - spare_bytes); - } - else - { - final_fn(&buffer[0], buffer_pos); - } - } - -} diff --git a/src/utils/buf_op/buf_op.h b/src/utils/buf_op/buf_op.h deleted file mode 100644 index cc864c47d..000000000 --- a/src/utils/buf_op/buf_op.h +++ /dev/null @@ -1,45 +0,0 @@ -/** -* Buffering Central -* (C) 2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_BUFFERED_OPTION_H__ -#define BOTAN_BUFFERED_OPTION_H__ - -#include <botan/types.h> -#include <tr1/functional> -#include <vector> - -namespace Botan { - -class BOTAN_DLL Buffered_Operation - { - public: - typedef std::tr1::function<void (const byte[], size_t)> callback_fn; - - void write(const byte input[], size_t input_size); - - void final(); - - void reset(); - - size_t current_position() const { return buffer_pos; } - - Buffered_Operation(callback_fn main_block, - callback_fn final_block, - size_t main_buf_mod, - size_t final_minimum = 0); - - private: - callback_fn main_fn, final_fn; - size_t final_minimum, main_block_mod; - - std::vector<byte> buffer; - size_t buffer_pos; - }; - -} - -#endif diff --git a/src/utils/buf_op/info.txt b/src/utils/buf_op/info.txt deleted file mode 100644 index 657a1e0c4..000000000 --- a/src/utils/buf_op/info.txt +++ /dev/null @@ -1,11 +0,0 @@ -define BUFFERED_OPERATION - -uses_tr1 yes - -<source> -buf_op.cpp -</source> - -<header:public> -buf_op.h -</header:public> |