Botan 3.1.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 <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 protected:
58 /**
59 * @param in some input for the filter
60 * @param length the length of in
61 */
62 virtual void send(const uint8_t in[], size_t length);
63
64 /**
65 * @param in some input for the filter
66 */
67 void send(uint8_t in) { send(&in, 1); }
68
69 /**
70 * @param in some input for the filter
71 */
72 template <typename Alloc>
73 void send(const std::vector<uint8_t, Alloc>& in) {
74 send(in.data(), in.size());
75 }
76
77 /**
78 * @param in some input for the filter
79 * @param length the number of bytes of in to send
80 */
81 template <typename Alloc>
82 void send(const std::vector<uint8_t, Alloc>& in, size_t length) {
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
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, m_filter_owns;
138
139 // true if filter belongs to a pipe --> prohibit filter sharing!
140 bool m_owned;
141};
142
143/**
144* This is the abstract Fanout_Filter base class.
145**/
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} // namespace Botan
169
170#endif
#define BOTAN_ASSERT_NOMSG(expr)
Definition: assert.h:59
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:53
void send(uint8_t in)
Definition: filter.h:67
void send(const std::vector< uint8_t, Alloc > &in)
Definition: filter.h:73
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:82
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:20
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