Botan 3.0.0-alpha0
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 ()
 

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 66 of file secqueue.cpp.

67 {
68 m_bytes_read = 0;
69 set_next(nullptr, 0);
70 m_head = m_tail = new SecureQueueNode;
71 }
void set_next(Filter *f[], size_t n)
Definition: filter.h:155

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 76 of file secqueue.cpp.

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

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

◆ ~SecureQueue()

Botan::SecureQueue::~SecureQueue ( )
inline

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

157{ Filter::attach(f); }

Referenced by 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:211

◆ 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 39 of file data_src.cpp.

40 {
41 uint8_t buf[64] = { 0 };
42 size_t discarded = 0;
43
44 while(n)
45 {
46 const size_t got = this->read(buf, std::min(n, sizeof(buf)));
47 discarded += got;
48 n -= got;
49
50 if(got == 0)
51 break;
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 232 of file secqueue.cpp.

233 {
234 return (size() == 0);
235 }

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 */ }

◆ 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 227 of file secqueue.cpp.

228 {
229 return (size() == 0);
230 }

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 203 of file secqueue.cpp.

204 {
205 return m_bytes_read;
206 }

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 59 of file data_src.h.

59{ return ""; }

◆ incr_owns()

void Botan::Fanout_Filter::incr_owns ( )
inlineprotectedinherited

Increment the number of filters past us that we own

Definition at line 151 of file filter.h.

151{ ++m_filter_owns; }

Referenced by 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.

110 {
111 if(this == &input)
112 return *this;
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 {
120 write(&temp->m_buffer[temp->m_start], temp->m_end - temp->m_start);
121 temp = temp->m_next;
122 }
123 return (*this);
124 }

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 172 of file secqueue.cpp.

173 {
174 SecureQueueNode* current = m_head;
175
176 while(offset && current)
177 {
178 if(offset >= current->size())
179 {
180 offset -= current->size();
181 current = current->m_next;
182 }
183 else
184 break;
185 }
186
187 size_t got = 0;
188 while(length && current)
189 {
190 const size_t n = current->peek(output, length, offset);
191 offset = 0;
192 output += n;
193 got += n;
194 length -= n;
195 current = current->m_next;
196 }
197 return got;
198 }

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 31 of file data_src.cpp.

32 {
33 return peek(&out, 1, 0);
34 }
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 149 of file secqueue.cpp.

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

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 23 of file data_src.cpp.

24 {
25 return read(&out, 1);
26 }

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

72 {
73 send(in.data(), in.size());
74 }
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 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:67

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.empty())
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 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 65 of file filter.h.

65{ 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 155 of file filter.h.

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

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

◆ set_port()

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

Definition at line 153 of file filter.h.

153{ Filter::set_port(n); }

Referenced by Botan::Fork::set_port().

◆ size()

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

Definition at line 211 of file secqueue.cpp.

212 {
213 SecureQueueNode* current = m_head;
214 size_t count = 0;
215
216 while(current)
217 {
218 count += current->size();
219 current = current->m_next;
220 }
221 return count;
222 }

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

40{ /* default empty */ }

◆ 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 129 of file secqueue.cpp.

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

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


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