Botan  2.7.0
Crypto and TLS for C++11
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)
 
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)
 
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 ()
 
virtual void send (const uint8_t in[], size_t length)
 
void send (uint8_t in)
 
void send (const secure_vector< uint8_t > &in)
 
void send (const std::vector< uint8_t > &in)
 
void send (const secure_vector< uint8_t > &in, size_t length)
 
void send (const std::vector< uint8_t > &in, size_t length)
 
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/2]

Botan::SecureQueue::SecureQueue ( )

SecureQueue default constructor (creates empty queue)

Definition at line 61 of file secqueue.cpp.

References Botan::Fanout_Filter::set_next().

62  {
63  m_bytes_read = 0;
64  set_next(nullptr, 0);
65  m_head = m_tail = new SecureQueueNode;
66  }
void set_next(Filter *f[], size_t n)
Definition: filter.h:162

◆ SecureQueue() [2/2]

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

SecureQueue copy constructor

Parameters
otherthe queue to copy

Definition at line 71 of file secqueue.cpp.

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

71  :
73  {
74  m_bytes_read = 0;
75  set_next(nullptr, 0);
76 
77  m_head = m_tail = new SecureQueueNode;
78  SecureQueueNode* temp = input.m_head;
79  while(temp)
80  {
81  write(&temp->m_buffer[temp->m_start], temp->m_end - temp->m_start);
82  temp = temp->m_next;
83  }
84  }
void set_next(Filter *f[], size_t n)
Definition: filter.h:162
void write(const uint8_t[], size_t) override
Definition: secqueue.cpp:124
DataSource()=default
friend class Fanout_Filter
Definition: filter.h:115

◆ ~SecureQueue()

Botan::SecureQueue::~SecureQueue ( )
inline

Definition at line 61 of file secqueue.h.

61 { destroy(); }

Member Function Documentation

◆ attach()

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

Definition at line 164 of file filter.h.

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

164 { Filter::attach(f); }

◆ 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:206

◆ 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.

References Botan::DataSource::read().

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) BOTAN_WARN_UNUSED_RESULT=0

◆ empty()

bool Botan::SecureQueue::empty ( ) const

Definition at line 227 of file secqueue.cpp.

References size().

228  {
229  return (size() == 0);
230  }
size_t size() const
Definition: secqueue.cpp:206

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

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

References size().

223  {
224  return (size() == 0);
225  }
size_t size() const
Definition: secqueue.cpp:206

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

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

199  {
200  return m_bytes_read;
201  }

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

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

158 { ++m_filter_owns; }

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

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

SecureQueue assignment

Parameters
otherthe queue to copy

Definition at line 104 of file secqueue.cpp.

References get_bytes_read(), and write().

105  {
106  if(this == &input)
107  return *this;
108 
109  destroy();
110  m_bytes_read = input.get_bytes_read();
111  m_head = m_tail = new SecureQueueNode;
112  SecureQueueNode* temp = input.m_head;
113  while(temp)
114  {
115  write(&temp->m_buffer[temp->m_start], temp->m_end - temp->m_start);
116  temp = temp->m_next;
117  }
118  return (*this);
119  }
void write(const uint8_t[], size_t) override
Definition: secqueue.cpp:124

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

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

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

◆ 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.

References Botan::DataSource::peek().

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

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

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

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

145  {
146  size_t got = 0;
147  while(length && m_head)
148  {
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  {
155  SecureQueueNode* holder = m_head->m_next;
156  delete m_head;
157  m_head = holder;
158  }
159  }
160  m_bytes_read += got;
161  return got;
162  }

◆ 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.

References Botan::DataSource::read().

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

24  {
25  return read(&out, 1);
26  }
virtual size_t read(uint8_t out[], size_t length) BOTAN_WARN_UNUSED_RESULT=0

◆ send() [1/6]

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.

References Botan::Filter::write().

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

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

◆ send() [2/6]

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

Definition at line 65 of file filter.h.

References Botan::Filter::send().

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

65 { send(&in, 1); }
virtual void send(const uint8_t in[], size_t length)
Definition: filter.cpp:27

◆ send() [3/6]

void Botan::Filter::send ( const secure_vector< uint8_t > &  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 70 of file filter.h.

References Botan::Filter::send().

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

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

◆ send() [4/6]

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

Definition at line 75 of file filter.h.

References Botan::Filter::send().

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

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

◆ send() [5/6]

void Botan::Filter::send ( const secure_vector< uint8_t > &  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  send(in.data(), length);
84  }
virtual void send(const uint8_t in[], size_t length)
Definition: filter.cpp:27

◆ send() [6/6]

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

Definition at line 90 of file filter.h.

91  {
92  send(in.data(), length);
93  }
virtual void send(const uint8_t in[], size_t length)
Definition: filter.cpp:27

◆ set_next()

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

Definition at line 162 of file filter.h.

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

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

◆ set_port()

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

Definition at line 160 of file filter.h.

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

160 { Filter::set_port(n); }

◆ size()

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

Definition at line 206 of file secqueue.cpp.

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

207  {
208  SecureQueueNode* current = m_head;
209  size_t count = 0;
210 
211  while(current)
212  {
213  count += current->size();
214  current = current->m_next;
215  }
216  return count;
217  }

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

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

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

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