Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | List of all members
Botan::SecureQueue Class Reference

`#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 ()
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

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 }
Botan::Fanout_Filter::set_next
void set_next(Filter *f[], size_t n)
Definition: filter.h:162

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

SecureQueue copy constructor

Parameters

  other | the queue to copy

Definition at line 71 of file secqueue.cpp.

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

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::Fanout_Filter::set_next
void set_next(Filter *f[], size_t n)
Definition: filter.h:162
Botan::SecureQueue::write
void write(const uint8_t[], size_t) override
Definition: secqueue.cpp:121
Botan::DataSource::DataSource
DataSource()=default
Botan::Filter::Fanout_Filter
friend class Fanout_Filter
Definition: filter.h:115

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

Definition at line 61 of file secqueue.h.

61 { destroy(); }

## Member Function Documentation

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

Definition at line 164 of file filter.h.

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

164 { Filter::attach(f); }

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 42 of file secqueue.h.

42 { return false; }

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

Implements Botan::DataSource.

Definition at line 35 of file secqueue.h.

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

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

References Botan::CT::min(), and Botan::DataSource::read().

39 {
40 uint8_t buf[64] = { 0 };
41 size_t discarded = 0;
42
43 while(n)
44 {
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 return discarded;
54 }
Botan::DataSource::read
virtual size_t read(uint8_t out[], size_t length) BOTAN_WARN_UNUSED_RESULT=0
Botan::CT::min
T min(T a, T b)
Definition: ct_utils.h:180

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

Definition at line 224 of file secqueue.cpp.

References size().

225 {
226 return (size() == 0);
227 }
Botan::SecureQueue::size
size_t size() const
Definition: secqueue.cpp:203

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

Definition at line 46 of file filter.h.

46 {}

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 still data to read, false otherwise

Implements Botan::DataSource.

Definition at line 219 of file secqueue.cpp.

References size().

220 {
221 return (size() == 0);
222 }
Botan::SecureQueue::size
size_t size() const
Definition: secqueue.cpp:203

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

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

196 {
197 return m_bytes_read;
198 }

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 ""; }

void Botan::Fanout_Filter::incr_owns | ( |  | ) |
| inline protected inherited

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; }

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

Returns
  descriptive name for this filter

Implements Botan::Filter.

Definition at line 23 of file secqueue.h.

23 { return "Queue"; }

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

SecureQueue assignment

Parameters

  other | the queue to copy

Definition at line 104 of file secqueue.cpp.

References get_bytes_read(), and write().

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

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

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

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

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

References Botan::DataSource::peek().

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

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

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

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

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

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

References Botan::DataSource::read().

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

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

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.

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::Hash_Filter::end_msg(), Botan::MAC_Filter::end_msg(), Botan::StreamCipher_Filter::write(), 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 }
Botan::Filter::write
virtual void write(const uint8_t input[], size_t length)=0

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.

References Botan::Filter::send().

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

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

void Botan::Filter::send | ( | const secure_vector< uint8_t > & | in | ) |
| inline protected inherited

Parameters

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

void Botan::Filter::send | ( | const std::vector< uint8_t > & | in | ) |
| inline protected inherited

Parameters

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

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

void Botan::Filter::send | ( | const std::vector< uint8_t > & | 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 90 of file filter.h.

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

void Botan::Fanout_Filter::set_next | ( | Filter * | f[],
|  | size_t | n
| ) |  |
| inline protected inherited

Definition at line 162 of file filter.h.

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

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

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

Definition at line 160 of file filter.h.

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

160 { Filter::set_port(n); }

size_t Botan::SecureQueue::size | ( |  | ) | const

Returns
  number of bytes available in the queue

Definition at line 203 of file secqueue.cpp.

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

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

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 {}

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

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

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

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

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