9#include <botan/internal/secqueue.h>
11#include <botan/mem_ops.h>
19class SecureQueueNode
final {
31 SecureQueueNode(
const SecureQueueNode& other) =
delete;
32 SecureQueueNode(SecureQueueNode&& other) =
delete;
33 SecureQueueNode& operator=(
const SecureQueueNode& other) =
delete;
34 SecureQueueNode& operator=(SecureQueueNode&& other) =
delete;
36 size_t write(
const uint8_t input[],
size_t length) {
37 size_t copied = std::min<size_t>(length, m_buffer.size() - m_end);
38 copy_mem(m_buffer.data() + m_end, input, copied);
43 size_t read(uint8_t output[],
size_t length) {
44 size_t copied = std::min(length, m_end - m_start);
45 copy_mem(output, m_buffer.data() + m_start, copied);
50 size_t peek(uint8_t output[],
size_t length,
size_t offset = 0) {
51 const size_t left = m_end - m_start;
55 size_t copied = std::min(length, left - offset);
56 copy_mem(output, m_buffer.data() + m_start + offset, copied);
60 size_t size()
const {
return (m_end - m_start); }
63 friend class SecureQueue;
64 SecureQueueNode* m_next;
66 size_t m_start, m_end;
75 m_head = m_tail =
new SecureQueueNode;
85 m_head = m_tail =
new SecureQueueNode;
86 SecureQueueNode* temp = input.m_head;
88 write(&temp->m_buffer[temp->m_start], temp->m_end - temp->m_start);
96void SecureQueue::destroy() {
97 SecureQueueNode* temp = m_head;
99 SecureQueueNode* holder = temp->m_next;
103 m_head = m_tail =
nullptr;
116 m_head = m_tail =
new SecureQueueNode;
117 SecureQueueNode* temp = input.m_head;
119 write(&temp->m_buffer[temp->m_start], temp->m_end - temp->m_start);
130 m_head = m_tail =
new SecureQueueNode;
133 const size_t n = m_tail->write(input, length);
137 m_tail->m_next =
new SecureQueueNode;
138 m_tail = m_tail->m_next;
148 while(length && m_head) {
149 const size_t n = m_head->read(output, length);
153 if(m_head->size() == 0) {
154 SecureQueueNode* holder = m_head->m_next;
167 SecureQueueNode* current = m_head;
169 while(offset && current) {
170 if(offset >= current->size()) {
171 offset -= current->size();
172 current = current->m_next;
179 while(length && current) {
180 const size_t n = current->peek(output, length, offset);
185 current = current->m_next;
201 SecureQueueNode* current = m_head;
205 count += current->size();
206 current = current->m_next;
215 return (
size() == 0);
219 return (
size() == 0);
void set_next(Filter *f[], size_t n)
bool end_of_data() const override
SecureQueue & operator=(const SecureQueue &other)
size_t read(uint8_t[], size_t) override
void write(const uint8_t[], size_t) override
size_t get_bytes_read() const override
size_t peek(uint8_t[], size_t, size_t=0) const override
int(* final)(unsigned char *, CTX *)
#define BOTAN_DEFAULT_BUFFER_SIZE
std::vector< T, secure_allocator< T > > secure_vector
constexpr void copy_mem(T *out, const T *in, size_t n)