aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/buf_op/buf_op.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-12-27 00:55:44 +0000
committerlloyd <[email protected]>2009-12-27 00:55:44 +0000
commit02954c2ec665809b8cc7e333e32fd710e04e613e (patch)
tree6d50e933b813480b5dee7fce262beaa3d770a3b4 /src/utils/buf_op/buf_op.h
parent3278adc183efac99ae2779069ce1badae77982c1 (diff)
Add a generalized Buffered_Operation. Relies on tr1 for sane callbacks
(std::tr1::function).
Diffstat (limited to 'src/utils/buf_op/buf_op.h')
-rw-r--r--src/utils/buf_op/buf_op.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/utils/buf_op/buf_op.h b/src/utils/buf_op/buf_op.h
new file mode 100644
index 000000000..cc864c47d
--- /dev/null
+++ b/src/utils/buf_op/buf_op.h
@@ -0,0 +1,45 @@
+/**
+* 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