3
* (C) 1999-2007 Jack Lloyd
6
* Botan is released under the Simplified BSD License (see license.txt)
9
#ifndef BOTAN_BASEFILT_H_
10
#define BOTAN_BASEFILT_H_
12
#include <botan/filter.h>
14
#if defined(BOTAN_TARGET_OS_HAS_THREADS)
21
* BitBucket is a filter which simply discards all inputs
23
class BOTAN_PUBLIC_API(2,0) BitBucket final : public Filter
26
void write(const uint8_t[], size_t) override { /* discard */ }
28
std::string name() const override { return "BitBucket"; }
32
* This class represents Filter chains. A Filter chain is an ordered
33
* concatenation of Filters, the input to a Chain sequentially passes
34
* through all the Filters contained in the Chain.
37
class BOTAN_PUBLIC_API(2,0) Chain final : public Fanout_Filter
40
void write(const uint8_t input[], size_t length) override { send(input, length); }
42
std::string name() const override;
45
* Construct a chain of up to four filters. The filters are set
46
* up in the same order as the arguments.
48
Chain(Filter* = nullptr, Filter* = nullptr,
49
Filter* = nullptr, Filter* = nullptr);
52
* Construct a chain from range of filters
53
* @param filter_arr the list of filters
54
* @param length how many filters
56
Chain(Filter* filter_arr[], size_t length);
60
* This class represents a fork filter, whose purpose is to fork the
61
* flow of data. It causes an input message to result in n messages at
62
* the end of the filter, where n is the number of forks.
64
class BOTAN_PUBLIC_API(2,0) Fork : public Fanout_Filter
67
void write(const uint8_t input[], size_t length) override { send(input, length); }
68
void set_port(size_t n) { Fanout_Filter::set_port(n); }
70
std::string name() const override;
73
* Construct a Fork filter with up to four forks.
75
Fork(Filter*, Filter*, Filter* = nullptr, Filter* = nullptr);
78
* Construct a Fork from range of filters
79
* @param filter_arr the list of filters
80
* @param length how many filters
82
Fork(Filter* filter_arr[], size_t length);
85
#if defined(BOTAN_TARGET_OS_HAS_THREADS)
88
* This class is a threaded version of the Fork filter. While this uses
89
* threads, the class itself is NOT thread-safe. This is meant as a drop-
90
* in replacement for Fork where performance gains are possible.
92
class BOTAN_PUBLIC_API(2,0) Threaded_Fork final : public Fork
95
std::string name() const override;
98
* Construct a Threaded_Fork filter with up to four forks.
100
Threaded_Fork(Filter*, Filter*, Filter* = nullptr, Filter* = nullptr);
103
* Construct a Threaded_Fork from range of filters
104
* @param filter_arr the list of filters
105
* @param length how many filters
107
Threaded_Fork(Filter* filter_arr[], size_t length);
112
void set_next(Filter* f[], size_t n);
113
void send(const uint8_t in[], size_t length) override;
114
void thread_delegate_work(const uint8_t input[], size_t length);
115
void thread_entry(Filter* filter);
117
std::vector<std::shared_ptr<std::thread>> m_threads;
118
std::unique_ptr<struct Threaded_Fork_Data> m_thread_data;