Botan 3.13.0
Crypto and TLS for C&
Botan::Fork Class Reference

#include <filters.h>

Inheritance diagram for Botan::Fork:
Botan::Fanout_Filter Botan::Filter

Public Member Functions

virtual bool attachable ()
virtual void end_msg ()
 Fork (Filter *f1, Filter *f2, Filter *f3=nullptr, Filter *f4=nullptr)
 Fork (Filter *filter_arr[], size_t length)
std::string name () const override
void set_port (size_t n)
virtual void start_msg ()
void write (const uint8_t input[], size_t length) override

Protected Member Functions

void attach (Filter *f)
void incr_owns ()
virtual void send (const uint8_t in[], size_t length)
void send (std::span< const uint8_t > in)
void send (std::span< const uint8_t > in, size_t length)
void send (uint8_t in)
void set_next (Filter *f[], size_t n)

Detailed Description

This class represents a fork filter, whose purpose is to fork the flow of data. It causes an input message to result in n messages at the end of the filter, where n is the number of forks.

Definition at line 832 of file filters.h.

Constructor & Destructor Documentation

◆ Fork() [1/2]

Botan::Fork::Fork ( Filter * f1,
Filter * f2,
Filter * f3 = nullptr,
Filter * f4 = nullptr )

Construct a Fork filter with up to four forks.

Definition at line 48 of file basefilt.cpp.

48 {
49 Filter* filters[4] = {f1, f2, f3, f4};
50 set_next(filters, 4);
51}
void set_next(Filter *f[], size_t n)
Definition filter.h:177
Filter(const Filter &)=delete

References Botan::Fanout_Filter::set_next().

◆ Fork() [2/2]

Botan::Fork::Fork ( Filter * filter_arr[],
size_t length )

Construct a Fork from range of filters

Parameters
filter_arrthe list of filters
lengthhow many filters

Definition at line 56 of file basefilt.cpp.

56 {
57 set_next(filters, count);
58}

References Botan::Fanout_Filter::set_next().

Member Function Documentation

◆ attach()

void Botan::Fanout_Filter::attach ( Filter * f)
inlineprotectedinherited

Attach a filter to the end of this filter chain

Parameters
fthe filter to attach

Definition at line 184 of file filter.h.

184{ Filter::attach(f); }

References Botan::Filter::Filter().

Referenced by Botan::Chain::Chain(), and Botan::Chain::Chain().

◆ attachable()

virtual bool Botan::Filter::attachable ( )
inlinevirtualinherited

Check whether this filter is an attachable filter.

Returns
true if this filter is attachable, false otherwise

Reimplemented in Botan::DataSink, and Botan::SecureQueue.

Definition at line 53 of file filter.h.

53{ return true; }

◆ end_msg()

virtual void Botan::Filter::end_msg ( )
inlinevirtualinherited

Notify that the current message is finished; flush buffers and do end-of-message processing (if any).

Reimplemented in Botan::Base64_Decoder, Botan::Base64_Encoder, Botan::DataSink_Stream, Botan::Hex_Decoder, and Botan::Hex_Encoder.

Definition at line 47 of file filter.h.

47{}

◆ incr_owns()

void Botan::Fanout_Filter::incr_owns ( )
inlineprotectedinherited

Increment the number of filters past us that we own

Definition at line 162 of file filter.h.

162{ ++m_filter_owns; }

Referenced by Botan::Chain::Chain(), and Botan::Chain::Chain().

◆ name()

std::string Botan::Fork::name ( ) const
inlineoverridevirtual

Return a descriptive name for this filter

Returns
"Fork"

Implements Botan::Filter.

Definition at line 852 of file filters.h.

852{ return "Fork"; }

◆ send() [1/4]

void Botan::Filter::send ( const uint8_t in[],
size_t length )
protectedvirtualinherited

Send some bytes to the next filter in the chain

Parameters
insome input for the filter
lengththe length of in

Definition at line 30 of file filter.cpp.

30 {
31 if(length == 0) {
32 return;
33 }
34
35 bool nothing_attached = true;
36 for(size_t j = 0; j != total_ports(); ++j) {
37 if(m_next[j] != nullptr) {
38 if(!m_write_queue.empty()) {
39 m_next[j]->write(m_write_queue.data(), m_write_queue.size());
40 }
41 m_next[j]->write(input, length);
42 nothing_attached = false;
43 }
44 }
45
46 if(nothing_attached) {
47 m_write_queue += std::make_pair(input, length);
48 } else {
49 m_write_queue.clear();
50 }
51}

Referenced by Botan::Base64_Decoder::end_msg(), Botan::Base64_Encoder::end_msg(), Botan::Hex_Decoder::end_msg(), Botan::Hex_Encoder::end_msg(), operator=(), send(), Botan::Base64_Decoder::write(), Botan::Chain::write(), Botan::Fork::write(), and Botan::Hex_Decoder::write().

◆ send() [2/4]

void Botan::Filter::send ( std::span< const uint8_t > in)
inlineprotectedinherited

Send some bytes to the next filter in the chain

Parameters
insome input for the filter

Definition at line 83 of file filter.h.

83{ send(in.data(), in.size()); }
virtual void send(const uint8_t in[], size_t length)
Definition filter.cpp:30

References send().

Referenced by send().

◆ send() [3/4]

void Botan::Filter::send ( std::span< const uint8_t > in,
size_t length )
protectedinherited

Send some bytes to the next filter in the chain

Parameters
insome input for the filter
lengththe number of bytes of in to send

This previously took a std::vector, for which the length field (allowing using just a prefix of the vector) somewhat made sense. It makes less sense now that we are using a span here; you can just use first to get a prefix.

Definition at line 22 of file filter.cpp.

22 {
23 BOTAN_ASSERT_NOMSG(length <= in.size());
24 send(in.data(), length);
25}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75

References BOTAN_ASSERT_NOMSG, and send().

◆ send() [4/4]

void Botan::Filter::send ( uint8_t in)
inlineprotectedinherited

Send some bytes to the next filter in the chain

Parameters
insome input for the filter

Definition at line 76 of file filter.h.

76{ send(&in, 1); }

References send().

Referenced by send().

◆ set_next()

void Botan::Fanout_Filter::set_next ( Filter * f[],
size_t n )
inlineprotectedinherited

Set the filters which follow this one

Parameters
fthe filters to attach
nthe number of filters in f

Definition at line 177 of file filter.h.

177{ Filter::set_next(f, n); }

References Botan::Filter::Filter().

Referenced by Botan::Fork::Fork(), Botan::Fork::Fork(), Botan::SecureQueue::SecureQueue(), and Botan::SecureQueue::SecureQueue().

◆ set_port()

void Botan::Fork::set_port ( size_t n)
inline

Select which fork subsequent output is sent to

Parameters
nthe index of the fork to select

Definition at line 846 of file filters.h.

void set_port(size_t n)
Definition filter.h:169

References Botan::Fanout_Filter::set_port().

◆ start_msg()

virtual void Botan::Filter::start_msg ( )
inlinevirtualinherited

Start a new message. Must be closed by end_msg() before another message can be started.

Definition at line 41 of file filter.h.

41{}

◆ write()

void Botan::Fork::write ( const uint8_t input[],
size_t length )
inlineoverridevirtual

Pass the input through to every fork

Parameters
inputthe input as a byte array
lengththe length of the byte array input

Implements Botan::Filter.

Definition at line 839 of file filters.h.

839{ send(input, length); }

References Botan::Filter::send().


The documentation for this class was generated from the following files: