Botan 3.13.0
Crypto and TLS for C&
Botan::Cipher_Mode_Filter Class Referencefinal

#include <filters.h>

Inheritance diagram for Botan::Cipher_Mode_Filter:
Botan::Keyed_Filter Botan::Buffered_Filter Botan::Filter

Public Member Functions

virtual bool attachable ()
 Cipher_Mode_Filter (Cipher_Mode *t)
 Cipher_Mode_Filter (std::unique_ptr< Cipher_Mode > t)
Key_Length_Specification key_spec () const override
std::string name () const override
void set_iv (const InitializationVector &iv) override
void set_key (const SymmetricKey &key) override
bool valid_iv_length (size_t length) const override
bool valid_keylength (size_t length) const

Protected Member Functions

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)

Private Member Functions

template<typename Alloc>
void write (const std::vector< uint8_t, Alloc > &in, size_t length)

Detailed Description

Filter interface for cipher modes

Definition at line 166 of file filters.h.

Constructor & Destructor Documentation

◆ Cipher_Mode_Filter() [1/2]

Botan::Cipher_Mode_Filter::Cipher_Mode_Filter ( Cipher_Mode * t)
explicit

Construct a filter wrapping the given cipher mode

Parameters
tthe cipher mode to use

Definition at line 28 of file cipher_filter.cpp.

28 :
29 Buffered_Filter(choose_update_size(mode->ideal_granularity()), mode->minimum_final_size()),
30 m_mode(mode),
31 m_buffer(m_mode->ideal_granularity()) {}
Buffered_Filter(size_t block_size, size_t final_minimum)
Definition buf_filt.cpp:18

References Botan::Buffered_Filter::Buffered_Filter().

Referenced by Cipher_Mode_Filter().

◆ Cipher_Mode_Filter() [2/2]

Botan::Cipher_Mode_Filter::Cipher_Mode_Filter ( std::unique_ptr< Cipher_Mode > t)
inlineexplicit

Construct a filter wrapping the given cipher mode

Parameters
tthe cipher mode to use

Definition at line 179 of file filters.h.

179: Cipher_Mode_Filter(t.release()) {}
Cipher_Mode_Filter(Cipher_Mode *t)

References Cipher_Mode_Filter().

Member Function Documentation

◆ 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; }

◆ key_spec()

Key_Length_Specification Botan::Cipher_Mode_Filter::key_spec ( ) const
overridevirtual

Return the key lengths supported by this filter

Returns
the key length specification

Implements Botan::Keyed_Filter.

Definition at line 45 of file cipher_filter.cpp.

45 {
46 return m_mode->key_spec();
47}

◆ name()

std::string Botan::Cipher_Mode_Filter::name ( ) const
overridevirtual

Return a descriptive name for this filter

Returns
the name of the underlying cipher mode

Implements Botan::Filter.

Definition at line 33 of file cipher_filter.cpp.

33 {
34 return m_mode->name();
35}

◆ 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_iv()

void Botan::Cipher_Mode_Filter::set_iv ( const InitializationVector & iv)
overridevirtual

Set the initialization vector for this filter

Parameters
ivthe initialization vector to set

Reimplemented from Botan::Keyed_Filter.

Definition at line 37 of file cipher_filter.cpp.

37 {
38 m_nonce = unlock(iv.bits_of());
39}
std::vector< T > unlock(const secure_vector< T > &in)
Definition secmem.h:155

References Botan::OctetString::bits_of(), and Botan::unlock().

◆ set_key()

void Botan::Cipher_Mode_Filter::set_key ( const SymmetricKey & key)
overridevirtual

Set the key of this filter

Parameters
keythe key to set

Implements Botan::Keyed_Filter.

Definition at line 41 of file cipher_filter.cpp.

41 {
42 m_mode->set_key(key);
43}

◆ valid_iv_length()

bool Botan::Cipher_Mode_Filter::valid_iv_length ( size_t length) const
overridevirtual

Check whether an IV length is valid for this filter

Parameters
lengththe IV length to be checked for validity
Returns
true if the IV length is valid

Reimplemented from Botan::Keyed_Filter.

Definition at line 49 of file cipher_filter.cpp.

49 {
50 return m_mode->valid_nonce_length(length);
51}

◆ valid_keylength()

bool Botan::Keyed_Filter::valid_keylength ( size_t length) const
inlineinherited

Check whether a key length is valid for this filter

Parameters
lengththe key length to be checked for validity
Returns
true if the key length is valid, false otherwise

Definition at line 148 of file filters.h.

148{ return key_spec().valid_keylength(length); }
bool valid_keylength(size_t length) const
Definition sym_algo.h:44
virtual Key_Length_Specification key_spec() const =0

References key_spec().


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