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

#include <secqueue.h>

Inheritance diagram for Botan::SecureQueue:
Botan::Fanout_Filter Botan::DataSource Botan::Filter

Public Member Functions

bool attachable () override
 
bool check_available (size_t n) override
 
size_t discard_next (size_t N)
 
bool empty () const
 
virtual void end_msg ()
 
bool end_of_data () const override
 
size_t get_bytes_read () const override
 
virtual std::string id () const
 
std::string name () const override
 
SecureQueueoperator= (const SecureQueue &other)
 
SecureQueueoperator= (SecureQueue &&other)=delete
 
size_t peek (uint8_t[], size_t, size_t=0) const override
 
size_t peek_byte (uint8_t &out) const
 
size_t read (uint8_t[], size_t) override
 
size_t read_byte (uint8_t &out)
 
 SecureQueue ()
 
 SecureQueue (const SecureQueue &other)
 
 SecureQueue (SecureQueue &&other)=delete
 
size_t size () const
 
virtual void start_msg ()
 
void write (const uint8_t[], size_t) override
 
 ~SecureQueue () override
 

Protected Member Functions

void attach (Filter *f)
 
void incr_owns ()
 
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)
 
void set_next (Filter *f[], size_t n)
 
void set_port (size_t n)
 

Detailed Description

A queue that knows how to zeroize itself

Definition at line 20 of file secqueue.h.

Constructor & Destructor Documentation

◆ SecureQueue() [1/3]

Botan::SecureQueue::SecureQueue ( SecureQueue && other)
delete

◆ SecureQueue() [2/3]

Botan::SecureQueue::SecureQueue ( )

SecureQueue default constructor (creates empty queue)

Definition at line 72 of file secqueue.cpp.

72 {
73 m_bytes_read = 0;
74 set_next(nullptr, 0);
75 m_head = m_tail = new SecureQueueNode;
76}
void set_next(Filter *f[], size_t n)
Definition filter.h:154

References Botan::Fanout_Filter::set_next().

◆ SecureQueue() [3/3]

Botan::SecureQueue::SecureQueue ( const SecureQueue & other)

SecureQueue copy constructor

Parameters
otherthe queue to copy

Definition at line 81 of file secqueue.cpp.

82 m_bytes_read = 0;
83 set_next(nullptr, 0);
84
85 m_head = m_tail = new SecureQueueNode;
86 SecureQueueNode* temp = input.m_head;
87 while(temp) {
88 write(&temp->m_buffer[temp->m_start], temp->m_end - temp->m_start);
89 temp = temp->m_next;
90 }
91}
DataSource()=default
friend class Fanout_Filter
Definition filter.h:106
void write(const uint8_t[], size_t) override
Definition secqueue.cpp:128

References Botan::Fanout_Filter::set_next(), and write().

◆ ~SecureQueue()

Botan::SecureQueue::~SecureQueue ( )
inlineoverride

Definition at line 64 of file secqueue.h.

64{ destroy(); }

Member Function Documentation

◆ attach()

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

Definition at line 156 of file filter.h.

156{ Filter::attach(f); }

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

◆ attachable()

bool Botan::SecureQueue::attachable ( )
inlineoverridevirtual

Check whether this filter is an attachable filter.

Returns
true if this filter is attachable, false otherwise

Reimplemented from Botan::Filter.

Definition at line 42 of file secqueue.h.

42{ return false; }

◆ check_available()

bool Botan::SecureQueue::check_available ( size_t n)
inlineoverridevirtual

Implements Botan::DataSource.

Definition at line 35 of file secqueue.h.

35{ return n <= size(); }
size_t size() const
Definition secqueue.cpp:200

◆ discard_next()

size_t Botan::DataSource::discard_next ( size_t N)
inherited

Discard the next N bytes of the data

Parameters
Nthe number of bytes to discard
Returns
number of bytes actually discarded

Definition at line 40 of file data_src.cpp.

40 {
41 uint8_t buf[64] = {0};
42 size_t discarded = 0;
43
44 while(n) {
45 const size_t got = this->read(buf, std::min(n, sizeof(buf)));
46 discarded += got;
47 n -= got;
48
49 if(got == 0) {
50 break;
51 }
52 }
53
54 return discarded;
55}
virtual size_t read(uint8_t out[], size_t length)=0

References Botan::DataSource::read().

◆ empty()

bool Botan::SecureQueue::empty ( ) const

Definition at line 218 of file secqueue.cpp.

218 {
219 return (size() == 0);
220}

References size().

◆ 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::DataSink_Stream, Botan::Base64_Encoder, Botan::Base64_Decoder, Botan::Hex_Encoder, and Botan::Hex_Decoder.

Definition at line 46 of file filter.h.

46 { /* default empty */
47 }

◆ end_of_data()

bool Botan::SecureQueue::end_of_data ( ) const
overridevirtual

Test whether the source still has data that can be read.

Returns
true if there is no more data to read, false otherwise

Implements Botan::DataSource.

Definition at line 214 of file secqueue.cpp.

214 {
215 return (size() == 0);
216}

References size().

◆ get_bytes_read()

size_t Botan::SecureQueue::get_bytes_read ( ) const
overridevirtual

Return how many bytes have been read so far.

Implements Botan::DataSource.

Definition at line 193 of file secqueue.cpp.

193 {
194 return m_bytes_read;
195}

Referenced by Botan::Output_Buffers::get_bytes_read(), and operator=().

◆ id()

virtual std::string Botan::DataSource::id ( ) const
inlinevirtualinherited

return the id of this data source

Returns
std::string representing the id of this data source

Reimplemented in Botan::DataSource_Stream.

Definition at line 61 of file data_src.h.

61{ return ""; }

◆ incr_owns()

void Botan::Fanout_Filter::incr_owns ( )
inlineprotectedinherited

Increment the number of filters past us that we own

Definition at line 150 of file filter.h.

150{ ++m_filter_owns; }

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

◆ name()

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

Implements Botan::Filter.

Definition at line 23 of file secqueue.h.

23{ return "Queue"; }

◆ operator=() [1/2]

SecureQueue & Botan::SecureQueue::operator= ( const SecureQueue & other)

SecureQueue assignment

Parameters
otherthe queue to copy

Definition at line 109 of file secqueue.cpp.

109 {
110 if(this == &input) {
111 return *this;
112 }
113
114 destroy();
115 m_bytes_read = input.get_bytes_read();
116 m_head = m_tail = new SecureQueueNode;
117 SecureQueueNode* temp = input.m_head;
118 while(temp) {
119 write(&temp->m_buffer[temp->m_start], temp->m_end - temp->m_start);
120 temp = temp->m_next;
121 }
122 return (*this);
123}

References get_bytes_read(), and write().

◆ operator=() [2/2]

SecureQueue & Botan::SecureQueue::operator= ( SecureQueue && other)
delete

◆ peek()

size_t Botan::SecureQueue::peek ( uint8_t out[],
size_t length,
size_t peek_offset = 0 ) const
overridevirtual

Read from the source but do not modify the internal offset. Consecutive calls to peek() will return portions of the source starting at the same position.

Parameters
outthe byte array to write the output to
lengththe length of the byte array out
peek_offsetthe offset into the stream to read at
Returns
length in bytes that was actually read and put into out

Implements Botan::DataSource.

Definition at line 166 of file secqueue.cpp.

166 {
167 SecureQueueNode* current = m_head;
168
169 while(offset && current) {
170 if(offset >= current->size()) {
171 offset -= current->size();
172 current = current->m_next;
173 } else {
174 break;
175 }
176 }
177
178 size_t got = 0;
179 while(length && current) {
180 const size_t n = current->peek(output, length, offset);
181 offset = 0;
182 output += n;
183 got += n;
184 length -= n;
185 current = current->m_next;
186 }
187 return got;
188}

Referenced by Botan::Output_Buffers::peek().

◆ peek_byte()

size_t Botan::DataSource::peek_byte ( uint8_t & out) const
inherited

Peek at one byte.

Parameters
outan output byte
Returns
length in bytes that was actually read and put into out

Definition at line 33 of file data_src.cpp.

33 {
34 return peek(&out, 1, 0);
35}
virtual size_t peek(uint8_t out[], size_t length, size_t peek_offset) const =0

References Botan::DataSource::peek().

Referenced by Botan::ASN1::maybe_BER().

◆ read()

size_t Botan::SecureQueue::read ( uint8_t out[],
size_t length )
overridevirtual

Read from the source. Moves the internal offset so that every call to read will return a new portion of the source.

Parameters
outthe byte array to write the result to
lengththe length of the byte array out
Returns
length in bytes that was actually read and put into out

Implements Botan::DataSource.

Definition at line 146 of file secqueue.cpp.

146 {
147 size_t got = 0;
148 while(length && m_head) {
149 const size_t n = m_head->read(output, length);
150 output += n;
151 got += n;
152 length -= n;
153 if(m_head->size() == 0) {
154 SecureQueueNode* holder = m_head->m_next;
155 delete m_head;
156 m_head = holder;
157 }
158 }
159 m_bytes_read += got;
160 return got;
161}

Referenced by Botan::Output_Buffers::read().

◆ read_byte()

size_t Botan::DataSource::read_byte ( uint8_t & out)
inherited

Read one byte.

Parameters
outthe byte to read to
Returns
length in bytes that was actually read and put into out

Definition at line 26 of file data_src.cpp.

26 {
27 return read(&out, 1);
28}

References Botan::DataSource::read().

Referenced by Botan::PEM_Code::decode(), Botan::BER_Decoder::discard_remaining(), and Botan::ASN1::maybe_BER().

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

76 {
77 send(in.data(), in.size());
78 }
virtual void send(const uint8_t in[], size_t length)
Definition filter.cpp:27

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

85 {
86 BOTAN_ASSERT_NOMSG(length <= in.size());
87 send(in.data(), length);
88 }
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59

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.

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

Referenced by Botan::Base64_Encoder::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 70 of file filter.h.

70{ send(&in, 1); }

References Botan::Filter::send().

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

◆ set_next()

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

Definition at line 154 of file filter.h.

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

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

◆ set_port()

void Botan::Fanout_Filter::set_port ( size_t n)
inlineprotectedinherited

Definition at line 152 of file filter.h.

152{ Filter::set_port(n); }

◆ size()

size_t Botan::SecureQueue::size ( ) const
Returns
number of bytes available in the queue

Definition at line 200 of file secqueue.cpp.

200 {
201 SecureQueueNode* current = m_head;
202 size_t count = 0;
203
204 while(current) {
205 count += current->size();
206 current = current->m_next;
207 }
208 return count;
209}

Referenced by empty(), end_of_data(), and Botan::Output_Buffers::remaining().

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

39 { /* default empty */
40 }

◆ write()

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

Write a portion of a message to this filter.

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

Implements Botan::Filter.

Definition at line 128 of file secqueue.cpp.

128 {
129 if(!m_head) {
130 m_head = m_tail = new SecureQueueNode;
131 }
132 while(length) {
133 const size_t n = m_tail->write(input, length);
134 input += n;
135 length -= n;
136 if(length) {
137 m_tail->m_next = new SecureQueueNode;
138 m_tail = m_tail->m_next;
139 }
140 }
141}

Referenced by operator=(), and SecureQueue().


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