Botan 3.9.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 <span>
14#include <string>
15#include <vector>
16
17namespace Botan {
18
19/**
20* This class represents general abstract filter objects.
21*/
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 /**
44 * Notify that the current message is finished; flush buffers and
45 * do end-of-message processing (if any).
46 */
47 virtual void end_msg() { /* default empty */
48 }
49
50 /**
51 * Check whether this filter is an attachable filter.
52 * @return true if this filter is attachable, false otherwise
53 */
54 virtual bool attachable() { return true; }
55
56 virtual ~Filter() = default;
57
58 Filter(const Filter&) = delete;
59 Filter(Filter&&) = delete;
60 Filter& operator=(const Filter&) = delete;
61 Filter& operator=(Filter&&) = delete;
62
63 protected:
64 /**
65 * @param in some input for the filter
66 * @param length the length of in
67 */
68 virtual void send(const uint8_t in[], size_t length);
69
70 /**
71 * @param in some input for the filter
72 */
73 void send(uint8_t in) { send(&in, 1); }
74
75 /**
76 * @param in some input for the filter
77 */
78 void send(std::span<const uint8_t> in) { send(in.data(), in.size()); }
79
80 /**
81 * @param in some input for the filter
82 * @param length the number of bytes of in to send
83 *
84 * This previously took a std::vector, for which the length field (allowing
85 * using just a prefix of the vector) somewhat made sense. It makes less
86 * sense now that we are using a span here; you can just use `first` to get
87 * a prefix.
88 */
89 void send(std::span<const uint8_t> in, size_t length);
90
91 Filter();
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
112 size_t current_port() const { return m_port_num; }
113
114 /**
115 * Set the active port
116 * @param new_port the new value
117 */
118 void set_port(size_t new_port);
119
120 size_t owns() const { return m_filter_owns; }
121
122 /**
123 * Attach another filter to this one
124 * @param f filter to attach
125 */
126 void attach(Filter* f);
127
128 /**
129 * @param filters the filters to set
130 * @param count number of items in filters
131 */
132 void set_next(Filter* filters[], size_t count);
133 Filter* get_next() const;
134
135 secure_vector<uint8_t> m_write_queue;
136 std::vector<Filter*> m_next; // not owned
137 size_t m_port_num = 0;
138 size_t m_filter_owns = 0;
139
140 // true if filter belongs to a pipe --> prohibit filter sharing!
141 bool m_owned = false;
142};
143
144/**
145* This is the abstract Fanout_Filter base class.
146**/
148 protected:
149 /**
150 * Increment the number of filters past us that we own
151 */
152 void incr_owns() { ++m_filter_owns; }
153
154 void set_port(size_t n) { Filter::set_port(n); }
155
156 void set_next(Filter* f[], size_t n) { Filter::set_next(f, n); }
157
158 void attach(Filter* f) { Filter::attach(f); }
159};
160
161/**
162* The type of checking to be performed by decoders:
163* NONE - no checks, IGNORE_WS - perform checks, but ignore
164* whitespaces, FULL_CHECK - perform checks, also complain
165* about white spaces.
166*/
168
169} // namespace Botan
170
171#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
void set_next(Filter *f[], size_t n)
Definition filter.h:156
void set_port(size_t n)
Definition filter.h:154
void attach(Filter *f)
Definition filter.h:158
Filter(Filter &&)=delete
Filter(const Filter &)=delete
virtual void send(const uint8_t in[], size_t length)
Definition filter.cpp:30
virtual ~Filter()=default
virtual void end_msg()
Definition filter.h:47
virtual std::string name() const =0
virtual bool attachable()
Definition filter.h:54
void send(uint8_t in)
Definition filter.h:73
friend class Fanout_Filter
Definition filter.h:107
Filter & operator=(Filter &&)=delete
void send(std::span< const uint8_t > in)
Definition filter.h:78
virtual void write(const uint8_t input[], size_t length)=0
friend class Threaded_Fork
Definition filter.h:108
Filter & operator=(const Filter &)=delete
virtual void start_msg()
Definition filter.h:40
friend class Pipe
Definition filter.h:106
Decoder_Checking
Definition filter.h:167
@ FULL_CHECK
Definition filter.h:167
@ NONE
Definition filter.h:167
@ IGNORE_WS
Definition filter.h:167