Botan: src/filters/buf_filt.h Source File

Botan 1.10.16

buf_filt.h
Go to the documentation of this file.
1 /*
2 * Buffered Filter
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_BUFFERED_FILTER_H__
9 #define BOTAN_BUFFERED_FILTER_H__
10
11 #include <botan/secmem.h>
12
13 namespace Botan {
14
15 /**
16 * Filter mixin that breaks input into blocks, useful for
17 * cipher modes
18 */
19 class BOTAN_DLL Buffered_Filter
20 {
21 public:
22 /**
23 * Write bytes into the buffered filter, which will them emit them
24 * in calls to buffered_block in the subclass
25 * @param in the input bytes
26 * @param length of in in bytes
27 */
28 void write(const byte in[], size_t length);
29
30 /**
31 * Finish a message, emitting to buffered_block and buffered_final
32 * Will throw an exception if less than final_minimum bytes were
33 * written into the filter.
34 */
35 void end_msg();
36
37 /**
38 * Initialize a Buffered_Filter
39 * @param block_size the function buffered_block will be called
40 * with inputs which are a multiple of this size
41 * @param final_minimum the function buffered_final will be called
42 * with at least this many bytes.
43 */
44 Buffered_Filter(size_t block_size, size_t final_minimum);
45
46 virtual ~Buffered_Filter() {}
47 protected:
48 /**
49 * The block processor, implemented by subclasses
50 * @param input some input bytes
51 * @param length the size of input, guaranteed to be a multiple
52 * of block_size
53 */
54 virtual void buffered_block(const byte input[], size_t length) = 0;
55
56 /**
57 * The final block, implemented by subclasses
58 * @param input some input bytes
59 * @param length the size of input, guaranteed to be at least
60 * final_minimum bytes
61 */
62 virtual void buffered_final(const byte input[], size_t length) = 0;
63
64 /**
65 * @return block size of inputs
66 */
67 size_t buffered_block_size() const { return main_block_mod; }
68
69 /**
70 * @return current position in the buffer
71 */
72 size_t current_position() const { return buffer_pos; }
73
74 /**
75 * Reset the buffer position
76 */
77 void buffer_reset() { buffer_pos = 0; }
78 private:
79 size_t main_block_mod, final_minimum;
80
81 SecureVector<byte> buffer;
82 size_t buffer_pos;
83 };
84
85 }
86
87 #endif
Botan::Buffered_Filter::~Buffered_Filter
virtual ~Buffered_Filter()
Definition: buf_filt.h:46
Botan::Buffered_Filter
Definition: buf_filt.h:19
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::Buffered_Filter::current_position
size_t current_position() const
Definition: buf_filt.h:72
Botan
Definition: algo_base.h:14
Botan::Buffered_Filter::buffer_reset
void buffer_reset()
Definition: buf_filt.h:77
Botan::Buffered_Filter::buffered_block_size
size_t buffered_block_size() const
Definition: buf_filt.h:67
Botan::SecureVector< byte >