Botan 2.19.2
Crypto and TLS for C&
Public Member Functions | Protected Member Functions | List of all members
Botan::Base64_Encoder Class Referencefinal

#include <filters.h>

Inheritance diagram for Botan::Base64_Encoder:
Botan::Filter

Public Member Functions

virtual bool attachable ()
 
 Base64_Encoder (bool breaks=false, size_t length=72, bool t_n=false)
 
void end_msg () override
 
std::string name () const override
 
virtual void start_msg ()
 
void write (const uint8_t input[], size_t length) override
 

Protected Member Functions

template<typename Alloc >
void send (const std::vector< uint8_t, Alloc > &in)
 
template<typename Alloc >
void send (const std::vector< uint8_t, Alloc > &in, size_t length)
 
virtual void send (const uint8_t in[], size_t length)
 
void send (uint8_t in)
 

Detailed Description

This class represents a Base64 encoder.

Definition at line 505 of file filters.h.

Constructor & Destructor Documentation

◆ Base64_Encoder()

Botan::Base64_Encoder::Base64_Encoder ( bool  breaks = false,
size_t  length = 72,
bool  t_n = false 
)

Create a base64 encoder.

Parameters
breakswhether to use line breaks in the output
lengththe length of the lines of the output
t_nwhether to use a trailing newline

Definition at line 18 of file b64_filt.cpp.

18 :
19 m_line_length(breaks ? length : 0),
20 m_trailing_newline(t_n && breaks),
21 m_in(48),
22 m_out(64),
23 m_position(0),
24 m_out_position(0)
25 {
26 }

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 52 of file filter.h.

52{ return true; }

◆ end_msg()

void Botan::Base64_Encoder::end_msg ( )
overridevirtual

Inform the Encoder that the current message shall be closed.

Reimplemented from Botan::Filter.

Definition at line 102 of file b64_filt.cpp.

103 {
104 encode_and_send(m_in.data(), m_position, true);
105
106 if(m_trailing_newline || (m_out_position && m_line_length))
107 send('\n');
108
109 m_out_position = m_position = 0;
110 }
virtual void send(const uint8_t in[], size_t length)
Definition: filter.cpp:27

References Botan::Filter::send().

◆ name()

std::string Botan::Base64_Encoder::name ( ) const
inlineoverridevirtual
Returns
descriptive name for this filter

Implements Botan::Filter.

Definition at line 508 of file filters.h.

508{ return "Base64_Encoder"; }

◆ send() [1/4]

template<typename Alloc >
void Botan::Filter::send ( const std::vector< uint8_t, Alloc > &  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 71 of file filter.h.

72 {
73 send(in.data(), in.size());
74 }

◆ send() [2/4]

template<typename Alloc >
void Botan::Filter::send ( const std::vector< uint8_t, Alloc > &  in,
size_t  length 
)
inlineprotectedinherited
Parameters
insome input for the filter
lengththe number of bytes of in to send

Definition at line 81 of file filter.h.

82 {
83 BOTAN_ASSERT_NOMSG(length <= in.size());
84 send(in.data(), length);
85 }
#define BOTAN_ASSERT_NOMSG(expr)
Definition: assert.h:68

References BOTAN_ASSERT_NOMSG.

◆ send() [3/4]

void Botan::Filter::send ( const uint8_t  in[],
size_t  length 
)
protectedvirtualinherited
Parameters
insome input for the filter
lengththe length of in

Definition at line 27 of file filter.cpp.

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

References Botan::Filter::write().

Referenced by end_msg(), Botan::Base64_Decoder::end_msg(), Botan::Hex_Encoder::end_msg(), Botan::Hex_Decoder::end_msg(), Botan::Base64_Decoder::write(), and Botan::Hex_Decoder::write().

◆ send() [4/4]

void Botan::Filter::send ( uint8_t  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 65 of file filter.h.

65{ send(&in, 1); }

References Botan::Filter::send().

Referenced by Botan::Filter::send().

◆ 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 40 of file filter.h.

40{ /* default empty */ }

◆ write()

void Botan::Base64_Encoder::write ( const uint8_t  input[],
size_t  length 
)
overridevirtual

Input a part of a message to the encoder.

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

Implements Botan::Filter.

Definition at line 79 of file b64_filt.cpp.

80 {
81 buffer_insert(m_in, m_position, input, length);
82 if(m_position + length >= m_in.size())
83 {
84 encode_and_send(m_in.data(), m_in.size());
85 input += (m_in.size() - m_position);
86 length -= (m_in.size() - m_position);
87 while(length >= m_in.size())
88 {
89 encode_and_send(input, m_in.size());
90 input += m_in.size();
91 length -= m_in.size();
92 }
93 copy_mem(m_in.data(), input, length);
94 m_position = 0;
95 }
96 m_position += length;
97 }
size_t buffer_insert(std::vector< T, Alloc > &buf, size_t buf_offset, const T input[], size_t input_length)
Definition: mem_ops.h:228
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:133

References Botan::buffer_insert(), and Botan::copy_mem().


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