Botan 2.13.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_PUBLIC_API(2,0) 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() { /* default empty */ }
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() { /* default empty */ }
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 template<typename Alloc>
71 void send(const std::vector<uint8_t, Alloc>& in)
72 {
73 send(in.data(), in.size());
74 }
75
76 /**
77 * @param in some input for the filter
78 * @param length the number of bytes of in to send
79 */
80 template<typename Alloc>
81 void send(const std::vector<uint8_t, Alloc>& in, size_t length)
82 {
83 BOTAN_ASSERT_NOMSG(length <= in.size());
84 send(in.data(), length);
85 }
86
87 Filter();
88
89 Filter(const Filter&) = delete;
90
91 Filter& operator=(const Filter&) = delete;
92
93 private:
94 /**
95 * Start a new message in *this and all following filters. Only for
96 * internal use, not intended for use in client applications.
97 */
98 void new_msg();
99
100 /**
101 * End a new message in *this and all following filters. Only for
102 * internal use, not intended for use in client applications.
103 */
104 void finish_msg();
105
106 friend class Pipe;
107 friend class Fanout_Filter;
108
109 size_t total_ports() const;
110 size_t current_port() const { return m_port_num; }
111
112 /**
113 * Set the active port
114 * @param new_port the new value
115 */
116 void set_port(size_t new_port);
117
118 size_t owns() const { return m_filter_owns; }
119
120 /**
121 * Attach another filter to this one
122 * @param f filter to attach
123 */
124 void attach(Filter* f);
125
126 /**
127 * @param filters the filters to set
128 * @param count number of items in filters
129 */
130 void set_next(Filter* filters[], size_t count);
131 Filter* get_next() const;
132
133 secure_vector<uint8_t> m_write_queue;
134 std::vector<Filter*> m_next; // not owned
135 size_t m_port_num, m_filter_owns;
136
137 // true if filter belongs to a pipe --> prohibit filter sharing!
138 bool m_owned;
139 };
140
141 /**
142 * This is the abstract Fanout_Filter base class.
143 **/
144 class BOTAN_PUBLIC_API(2,0) Fanout_Filter : public Filter
145 {
146 protected:
147 /**
148 * Increment the number of filters past us that we own
149 */
150 void incr_owns() { ++m_filter_owns; }
151
152 void set_port(size_t n) { Filter::set_port(n); }
153
154 void set_next(Filter* f[], size_t n) { Filter::set_next(f, n); }
155
156 void attach(Filter* f) { Filter::attach(f); }
157
158 private:
159 friend class Threaded_Fork;
160 using Filter::m_write_queue;
161 using Filter::total_ports;
162 using Filter::m_next;
163 };
164
165 /**
166 * The type of checking to be performed by decoders:
167 * NONE - no checks, IGNORE_WS - perform checks, but ignore
168 * whitespaces, FULL_CHECK - perform checks, also complain
169 * about white spaces.
170 */
171 enum Decoder_Checking { NONE, IGNORE_WS, FULL_CHECK };
172
173 }
174
175 #endif
Botan::Fanout_Filter::set_port
void set_port(size_t n)
Definition: filter.h:152
Botan::Fanout_Filter::attach
void attach(Filter *f)
Definition: filter.h:156
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::Fanout_Filter
Definition: filter.h:144
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:154
BOTAN_ASSERT_NOMSG
#define BOTAN_ASSERT_NOMSG(expr)
Definition: assert.h:68
Botan::Filter::send
void send(const std::vector< uint8_t, Alloc > &in)
Definition: filter.h:71
Botan::FULL_CHECK
Definition: filter.h:171
name
std::string name
Definition: commoncrypto_hash.cpp:23
Botan::Filter
Definition: filter.h:21
Botan::IGNORE_WS
Definition: filter.h:171
Botan::Filter::send
void send(const std::vector< uint8_t, Alloc > &in, size_t length)
Definition: filter.h:81
Botan::Fanout_Filter::incr_owns
void incr_owns()
Definition: filter.h:150
Botan::Filter::start_msg
virtual void start_msg()
Definition: filter.h:40
Botan
Definition: alg_id.cpp:13
Botan::NONE
Definition: filter.h:171
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:29
Botan::Decoder_Checking
Decoder_Checking
Definition: filter.h:171