Botan 3.0.0-alpha0
Crypto and TLS for C&
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
16namespace Botan {
17
18/**
19* This class represents general abstract filter objects.
20*/
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 friend class Threaded_Fork;
109
110 size_t total_ports() const;
111 size_t current_port() const { return m_port_num; }
112
113 /**
114 * Set the active port
115 * @param new_port the new value
116 */
117 void set_port(size_t new_port);
118
119 size_t owns() const { return m_filter_owns; }
120
121 /**
122 * Attach another filter to this one
123 * @param f filter to attach
124 */
125 void attach(Filter* f);
126
127 /**
128 * @param filters the filters to set
129 * @param count number of items in filters
130 */
131 void set_next(Filter* filters[], size_t count);
132 Filter* get_next() const;
133
134 secure_vector<uint8_t> m_write_queue;
135 std::vector<Filter*> m_next; // not owned
136 size_t m_port_num, m_filter_owns;
137
138 // true if filter belongs to a pipe --> prohibit filter sharing!
139 bool m_owned;
140 };
141
142/**
143* This is the abstract Fanout_Filter base class.
144**/
146 {
147 protected:
148 /**
149 * Increment the number of filters past us that we own
150 */
151 void incr_owns() { ++m_filter_owns; }
152
153 void set_port(size_t n) { Filter::set_port(n); }
154
155 void set_next(Filter* f[], size_t n) { Filter::set_next(f, n); }
156
157 void attach(Filter* f) { Filter::attach(f); }
158 };
159
160/**
161* The type of checking to be performed by decoders:
162* NONE - no checks, IGNORE_WS - perform checks, but ignore
163* whitespaces, FULL_CHECK - perform checks, also complain
164* about white spaces.
165*/
167
168}
169
170#endif
#define BOTAN_ASSERT_NOMSG(expr)
Definition: assert.h:67
void set_next(Filter *f[], size_t n)
Definition: filter.h:155
void set_port(size_t n)
Definition: filter.h:153
void attach(Filter *f)
Definition: filter.h:157
Filter(const Filter &)=delete
virtual ~Filter()=default
virtual void end_msg()
Definition: filter.h:46
virtual std::string name() const =0
virtual bool attachable()
Definition: filter.h:52
void send(uint8_t in)
Definition: filter.h:65
void send(const std::vector< uint8_t, Alloc > &in)
Definition: filter.h:71
virtual void write(const uint8_t input[], size_t length)=0
Filter & operator=(const Filter &)=delete
virtual void start_msg()
Definition: filter.h:40
void send(const std::vector< uint8_t, Alloc > &in, size_t length)
Definition: filter.h:81
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:13
Decoder_Checking
Definition: filter.h:166
@ FULL_CHECK
Definition: filter.h:166
@ NONE
Definition: filter.h:166
@ IGNORE_WS
Definition: filter.h:166