Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

filter.h
Go to the documentation of this file.
1 /*
2 * Filter
3 * (C) 1999-2007 Jack Lloyd
4 * (C) 2013 Joel Low
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9 #ifndef BOTAN_FILTER_H__
10 #define BOTAN_FILTER_H__
11
12 #include <botan/secmem.h>
13 #include <vector>
14 #include <string>
15
16 namespace Botan {
17
18 /**
19 * This class represents general abstract filter objects.
20 */
21 class BOTAN_DLL Filter
22 {
23 public:
24 /**
25 * @return descriptive name for this filter
26 */
27 virtual std::string name() const = 0;
28
29 /**
30 * Write a portion of a message to this filter.
31 * @param input the input as a byte array
32 * @param length the length of the byte array input
33 */
34 virtual void write(const uint8_t input[], size_t length) = 0;
35
36 /**
37 * Start a new message. Must be closed by end_msg() before another
38 * message can be started.
39 */
40 virtual void start_msg() {}
41
42 /**
43 * Notify that the current message is finished; flush buffers and
44 * do end-of-message processing (if any).
45 */
46 virtual void end_msg() {}
47
48 /**
49 * Check whether this filter is an attachable filter.
50 * @return true if this filter is attachable, false otherwise
51 */
52 virtual bool attachable() { return true; }
53
54 virtual ~Filter() = default;
55 protected:
56 /**
57 * @param in some input for the filter
58 * @param length the length of in
59 */
60 virtual void send(const uint8_t in[], size_t length);
61
62 /**
63 * @param in some input for the filter
64 */
65 void send(uint8_t in) { send(&in, 1); }
66
67 /**
68 * @param in some input for the filter
69 */
70 void send(const secure_vector<uint8_t>& in) { send(in.data(), in.size()); }
71
72 /**
73 * @param in some input for the filter
74 */
75 void send(const std::vector<uint8_t>& in) { send(in.data(), in.size()); }
76
77 /**
78 * @param in some input for the filter
79 * @param length the number of bytes of in to send
80 */
81 void send(const secure_vector<uint8_t>& in, size_t length)
82 {
83 send(in.data(), length);
84 }
85
86 /**
87 * @param in some input for the filter
88 * @param length the number of bytes of in to send
89 */
90 void send(const std::vector<uint8_t>& in, size_t length)
91 {
92 send(in.data(), length);
93 }
94
95 Filter();
96
97 Filter(const Filter&) = delete;
98
99 Filter& operator=(const Filter&) = delete;
100
101 private:
102 /**
103 * Start a new message in *this and all following filters. Only for
104 * internal use, not intended for use in client applications.
105 */
106 void new_msg();
107
108 /**
109 * End a new message in *this and all following filters. Only for
110 * internal use, not intended for use in client applications.
111 */
112 void finish_msg();
113
114 friend class Pipe;
115 friend class Fanout_Filter;
116
117 size_t total_ports() const;
118 size_t current_port() const { return m_port_num; }
119
120 /**
121 * Set the active port
122 * @param new_port the new value
123 */
124 void set_port(size_t new_port);
125
126 size_t owns() const { return m_filter_owns; }
127
128 /**
129 * Attach another filter to this one
130 * @param f filter to attach
131 */
132 void attach(Filter* f);
133
134 /**
135 * @param filters the filters to set
136 * @param count number of items in filters
137 */
138 void set_next(Filter* filters[], size_t count);
139 Filter* get_next() const;
140
141 secure_vector<uint8_t> m_write_queue;
142 std::vector<Filter*> m_next;
143 size_t m_port_num, m_filter_owns;
144
145 // true if filter belongs to a pipe --> prohibit filter sharing!
146 bool m_owned;
147 };
148
149 /**
150 * This is the abstract Fanout_Filter base class.
151 **/
152 class BOTAN_DLL Fanout_Filter : public Filter
153 {
154 protected:
155 /**
156 * Increment the number of filters past us that we own
157 */
158 void incr_owns() { ++m_filter_owns; }
159
160 void set_port(size_t n) { Filter::set_port(n); }
161
162 void set_next(Filter* f[], size_t n) { Filter::set_next(f, n); }
163
164 void attach(Filter* f) { Filter::attach(f); }
165
166 private:
167 friend class Threaded_Fork;
168 using Filter::m_write_queue;
169 using Filter::total_ports;
170 using Filter::m_next;
171 };
172
173 /**
174 * The type of checking to be performed by decoders:
175 * NONE - no checks, IGNORE_WS - perform checks, but ignore
176 * whitespaces, FULL_CHECK - perform checks, also complain
177 * about white spaces.
178 */
179 enum Decoder_Checking { NONE, IGNORE_WS, FULL_CHECK };
180
181 }
182
183 #endif
Botan::Fanout_Filter::set_port
void set_port(size_t n)
Definition: filter.h:160
Botan::Filter::send
void send(const secure_vector< uint8_t > &in)
Definition: filter.h:70
Botan::Fanout_Filter::attach
void attach(Filter *f)
Definition: filter.h:164
Botan::Fanout_Filter
Definition: filter.h:152
Botan::Filter::send
void send(uint8_t in)
Definition: filter.h:65
Botan::Fanout_Filter::set_next
void set_next(Filter *f[], size_t n)
Definition: filter.h:162
Botan::FULL_CHECK
Definition: filter.h:179
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::Filter::send
void send(const std::vector< uint8_t > &in, size_t length)
Definition: filter.h:90
Botan::Filter
Definition: filter.h:21
Botan::IGNORE_WS
Definition: filter.h:179
Botan::Fanout_Filter::incr_owns
void incr_owns()
Definition: filter.h:158
Botan::Filter::start_msg
virtual void start_msg()
Definition: filter.h:40
Botan::Filter::send
void send(const std::vector< uint8_t > &in)
Definition: filter.h:75
Botan
Definition: alg_id.cpp:13
Botan::Filter::send
void send(const secure_vector< uint8_t > &in, size_t length)
Definition: filter.h:81
Botan::NONE
Definition: filter.h:179
Botan::Filter::end_msg
virtual void end_msg()
Definition: filter.h:46
Botan::Filter::attachable
virtual bool attachable()
Definition: filter.h:52
Botan::Pipe
Definition: pipe.h:27
Botan::Decoder_Checking
Decoder_Checking
Definition: filter.h:179