Botan 2.19.5 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:

## 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
SecureQueue & | operator= (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 ()
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 22 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.

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

References Botan::Fanout_Filter::set_next().

## ◆ SecureQueue() [2/2]

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

SecureQueue copy constructor

Parameters

  other | the queue to copy

Definition at line 71 of file secqueue.cpp.

71 :
72 Fanout_Filter(), DataSource()
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 }
Botan::DataSource::DataSource
DataSource()=default
Botan::Filter::Fanout_Filter
friend class Fanout_Filter
Definition: filter.h:107
Botan::SecureQueue::write
void write(const uint8_t[], size_t) override
Definition: secqueue.cpp:124

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

## ◆ ~SecureQueue()

Botan::SecureQueue::~SecureQueue | ( |  | ) |
| inline

Definition at line 63 of file secqueue.h.

63{ destroy(); }

## Member Function Documentation

## ◆ attach()

void Botan::Fanout_Filter::attach | ( | Filter * | f | ) |
| inline protected inherited

Definition at line 156 of file filter.h.

156{ Filter::attach(f); }

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

## ◆ attachable()

bool Botan::SecureQueue::attachable | ( |  | ) |
| inline override virtual

Check whether this filter is an attachable filter.

Returns
  true if this filter is attachable, false otherwise

Reimplemented from Botan::Filter.

Definition at line 44 of file secqueue.h.

44{ return false; }

## ◆ check_available()

bool Botan::SecureQueue::check_available | ( | size_t | n | ) |
| inline override virtual

Implements Botan::DataSource.

Definition at line 37 of file secqueue.h.

37{ return n <= size(); }
Botan::SecureQueue::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

  N | the 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 }
Botan::DataSource::read
virtual size_t read(uint8_t out[], size_t length) BOTAN_WARN_UNUSED_RESULT=0

References Botan::DataSource::read().

## ◆ empty()

bool Botan::SecureQueue::empty | ( |  | ) | const

Definition at line 227 of file secqueue.cpp.

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

References size().

## ◆ end_msg()

virtual void Botan::Filter::end_msg | ( |  | ) |
| inline virtual inherited

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
| override virtual

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.

223 {
224 return (size() == 0);
225 }

References size().

## ◆ get_bytes_read()

size_t Botan::SecureQueue::get_bytes_read | ( |  | ) | const
| override virtual

Return how many bytes have been read so far.

Implements Botan::DataSource.

Definition at line 198 of file secqueue.cpp.

199 {
200 return m_bytes_read;
201 }

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

## ◆ id()

virtual std::string Botan::DataSource::id | ( |  | ) | const
| inline virtual inherited

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 | ( |  | ) |
| inline protected inherited

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().

## ◆ name()

std::string Botan::SecureQueue::name | ( |  | ) | const
| inline override virtual

Returns
  descriptive name for this filter

Implements Botan::Filter.

Definition at line 25 of file secqueue.h.

25{ return "Queue"; }

## ◆ operator=()

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

SecureQueue assignment

Parameters

  other | the queue to copy

Definition at line 104 of file secqueue.cpp.

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 }

References get_bytes_read(), and write().

## ◆ peek()

size_t Botan::SecureQueue::peek | ( | uint8_t | out[],
|  | size_t | length,
|  | size_t | peek_offset = `0`
| ) |  | const
| override virtual

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

  out | the byte array to write the output to
  length | the length of the byte array out
  peek_offset | the 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.

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 }

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

## ◆ peek_byte()

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

Peek at one byte.

Parameters

  out | an 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 }
Botan::DataSource::peek
virtual size_t peek(uint8_t out[], size_t length, size_t peek_offset) const BOTAN_WARN_UNUSED_RESULT=0

References Botan::DataSource::peek().

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

## ◆ read()

size_t Botan::SecureQueue::read | ( | uint8_t | out[],
|  | size_t | length
| ) |  |
| override virtual

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

Parameters

  out | the byte array to write the result to
  length | the 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.

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 }

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

## ◆ read_byte()

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

Read one byte.

Parameters

  out | the 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 | ) |
| inline protected inherited

Parameters

  in | some input for the filter

Definition at line 71 of file filter.h.

72 {
73 send(in.data(), in.size());
74 }
Botan::Filter::send
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
| ) |  |
| inline protected inherited

Parameters

  in | some input for the filter
  length | the 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 }
BOTAN_ASSERT_NOMSG
#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
| ) |  |
| protected virtual inherited

Parameters

  in | some input for the filter
  length | the 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 }
Botan::Filter::write
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 | ) |
| inline protected inherited

Parameters

  in | some 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
| ) |  |
| inline protected inherited

Definition at line 154 of file filter.h.

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

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

## ◆ set_port()

void Botan::Fanout_Filter::set_port | ( | size_t | n | ) |
| inline protected inherited

Definition at line 152 of file filter.h.

152{ 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 206 of file secqueue.cpp.

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 }

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

## ◆ start_msg()

virtual void Botan::Filter::start_msg | ( |  | ) |
| inline virtual inherited

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
| ) |  |
| override virtual

Write a portion of a message to this filter.

Parameters

  input | the input as a byte array
  length | the length of the byte array input

Implements Botan::Filter.

Definition at line 124 of file secqueue.cpp.

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 }

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

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

- src/lib/filters/secqueue.h
- src/lib/filters/secqueue.cpp