Botan 3.4.0
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 <string>
14#include <vector>
15
16namespace Botan {
17
18/**
19* This class represents general abstract filter objects.
20*/
22 public:
23 /**
24 * @return descriptive name for this filter
25 */
26 virtual std::string name() const = 0;
27
28 /**
29 * Write a portion of a message to this filter.
30 * @param input the input as a byte array
31 * @param length the length of the byte array input
32 */
33 virtual void write(const uint8_t input[], size_t length) = 0;
34
35 /**
36 * Start a new message. Must be closed by end_msg() before another
37 * message can be started.
38 */
39 virtual void start_msg() { /* default empty */
40 }
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 /**
50 * Check whether this filter is an attachable filter.
51 * @return true if this filter is attachable, false otherwise
52 */
53 virtual bool attachable() { return true; }
54
55 virtual ~Filter() = default;
56
57 Filter(const Filter&) = delete;
58 Filter& operator=(const Filter&) = delete;
59
60 protected:
61 /**
62 * @param in some input for the filter
63 * @param length the length of in
64 */
65 virtual void send(const uint8_t in[], size_t length);
66
67 /**
68 * @param in some input for the filter
69 */
70 void send(uint8_t in) { send(&in, 1); }
71
72 /**
73 * @param in some input for the filter
74 */
75 template <typename Alloc>
76 void send(const std::vector<uint8_t, Alloc>& in) {
77 send(in.data(), in.size());
78 }
79
80 /**
81 * @param in some input for the filter
82 * @param length the number of bytes of in to send
83 */
84 template <typename Alloc>
85 void send(const std::vector<uint8_t, Alloc>& in, size_t length) {
86 BOTAN_ASSERT_NOMSG(length <= in.size());
87 send(in.data(), length);
88 }
89
90 Filter();
91
92 private:
93 /**
94 * Start a new message in *this and all following filters. Only for
95 * internal use, not intended for use in client applications.
96 */
97 void new_msg();
98
99 /**
100 * End a new message in *this and all following filters. Only for
101 * internal use, not intended for use in client applications.
102 */
103 void finish_msg();
104
105 friend class Pipe;
106 friend class Fanout_Filter;
107 friend class Threaded_Fork;
108
109 size_t total_ports() const;
110
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 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
159/**
160* The type of checking to be performed by decoders:
161* NONE - no checks, IGNORE_WS - perform checks, but ignore
162* whitespaces, FULL_CHECK - perform checks, also complain
163* about white spaces.
164*/
166
167} // namespace Botan
168
169#endif
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
void set_next(Filter *f[], size_t n)
Definition filter.h:154
void set_port(size_t n)
Definition filter.h:152
void attach(Filter *f)
Definition filter.h:156
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:53
void send(uint8_t in)
Definition filter.h:70
void send(const std::vector< uint8_t, Alloc > &in)
Definition filter.h:76
virtual void write(const uint8_t input[], size_t length)=0
Filter & operator=(const Filter &)=delete
virtual void start_msg()
Definition filter.h:39
void send(const std::vector< uint8_t, Alloc > &in, size_t length)
Definition filter.h:85
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
Decoder_Checking
Definition filter.h:165
@ FULL_CHECK
Definition filter.h:165
@ NONE
Definition filter.h:165
@ IGNORE_WS
Definition filter.h:165