Botan 3.8.1
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& operator=(const Filter&) = delete;
60
61 protected:
62 /**
63 * @param in some input for the filter
64 * @param length the length of in
65 */
66 virtual void send(const uint8_t in[], size_t length);
67
68 /**
69 * @param in some input for the filter
70 */
71 void send(uint8_t in) { send(&in, 1); }
72
73 /**
74 * @param in some input for the filter
75 */
76 void send(std::span<const uint8_t> in) { send(in.data(), in.size()); }
77
78 /**
79 * @param in some input for the filter
80 * @param length the number of bytes of in to send
81 *
82 * This previously took a std::vector, for which the length field (allowing
83 * using just a prefix of the vector) somewhat made sense. It makes less
84 * sense now that we are using a span here; you can just use `first` to get
85 * a prefix.
86 */
87 void send(std::span<const uint8_t> in, size_t length);
88
89 Filter();
90
91 private:
92 /**
93 * Start a new message in *this and all following filters. Only for
94 * internal use, not intended for use in client applications.
95 */
96 void new_msg();
97
98 /**
99 * End a new message in *this and all following filters. Only for
100 * internal use, not intended for use in client applications.
101 */
102 void finish_msg();
103
104 friend class Pipe;
105 friend class Fanout_Filter;
106 friend class Threaded_Fork;
107
108 size_t total_ports() const;
109
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**/
145 protected:
146 /**
147 * Increment the number of filters past us that we own
148 */
149 void incr_owns() { ++m_filter_owns; }
150
151 void set_port(size_t n) { Filter::set_port(n); }
152
153 void set_next(Filter* f[], size_t n) { Filter::set_next(f, n); }
154
155 void attach(Filter* f) { Filter::attach(f); }
156};
157
158/**
159* The type of checking to be performed by decoders:
160* NONE - no checks, IGNORE_WS - perform checks, but ignore
161* whitespaces, FULL_CHECK - perform checks, also complain
162* about white spaces.
163*/
165
166} // namespace Botan
167
168#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:19
void set_next(Filter *f[], size_t n)
Definition filter.h:153
void set_port(size_t n)
Definition filter.h:151
void attach(Filter *f)
Definition filter.h:155
Filter(const Filter &)=delete
virtual void send(const uint8_t in[], size_t length)
Definition filter.cpp:33
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:71
friend class Fanout_Filter
Definition filter.h:105
void send(std::span< const uint8_t > in)
Definition filter.h:76
virtual void write(const uint8_t input[], size_t length)=0
friend class Threaded_Fork
Definition filter.h:106
Filter & operator=(const Filter &)=delete
virtual void start_msg()
Definition filter.h:40
friend class Pipe
Definition filter.h:104
Decoder_Checking
Definition filter.h:164
@ FULL_CHECK
Definition filter.h:164
@ NONE
Definition filter.h:164
@ IGNORE_WS
Definition filter.h:164