Botan 2.19.5 Crypto and TLS for C&

out_buf.cpp
Go to the documentation of this file.
1/*
2* Pipe Output Buffer
3* (C) 1999-2007,2011 Jack Lloyd
4* 2012 Markus Wanner
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#include <botan/internal/out_buf.h>
10#include <botan/secqueue.h>
11
12 namespace Botan {
13
14/*
15* Read data from a message
16*/
17 size_t Output_Buffers::read(uint8_t output[], size_t length,
18 Pipe::message_id msg)
19 {
20 SecureQueue* q = get(msg);
21 if(q)
22 return q->read(output, length);
23 return 0;
24 }
25
26/*
27* Peek at data in a message
28*/
29 size_t Output_Buffers::peek(uint8_t output[], size_t length,
30 size_t stream_offset,
31 Pipe::message_id msg) const
32 {
33 SecureQueue* q = get(msg);
34 if(q)
35 return q->peek(output, length, stream_offset);
36 return 0;
37 }
38
39/*
40* Check available bytes in a message
41*/
42 size_t Output_Buffers::remaining(Pipe::message_id msg) const
43 {
44 SecureQueue* q = get(msg);
45 if(q)
46 return q->size();
47 return 0;
48 }
49
50/*
51* Return the total bytes of a message that have already been read.
52*/
53 size_t Output_Buffers::get_bytes_read(Pipe::message_id msg) const
54 {
55 SecureQueue* q = get(msg);
56 if (q)
57 return q->get_bytes_read();
58 return 0;
59 }
60
61/*
62* Add a new output queue
63*/
64 void Output_Buffers::add(SecureQueue* queue)
65 {
66 BOTAN_ASSERT(queue, "queue was provided");
67
68 BOTAN_ASSERT(m_buffers.size() < m_buffers.max_size(),
69 "Room was available in container");
70
71 m_buffers.push_back(std::unique_ptr<SecureQueue>(queue));
72 }
73
74/*
75* Retire old output queues
76*/
77 void Output_Buffers::retire()
78 {
79 for(size_t i = 0; i != m_buffers.size(); ++i)
80 if(m_buffers[i] && m_buffers[i]->size() == 0)
81 {
82 m_buffers[i].reset();
83 }
84
85 while(m_buffers.size() && !m_buffers[0])
86 {
87 m_buffers.pop_front();
88 m_offset = m_offset + Pipe::message_id(1);
89 }
90 }
91
92/*
93* Get a particular output queue
94*/
95 SecureQueue* Output_Buffers::get(Pipe::message_id msg) const
96 {
97 if(msg < m_offset)
98 return nullptr;
99
100 BOTAN_ASSERT(msg < message_count(), "Message number is in range");
101
102 return m_buffers[msg-m_offset].get();
103 }
104
105/*
106* Return the total number of messages
107*/
108 Pipe::message_id Output_Buffers::message_count() const
109 {
110 return (m_offset + m_buffers.size());
111 }
112
113/*
114* Output_Buffers Constructor
115*/
116 Output_Buffers::Output_Buffers()
117 {
118 m_offset = 0;
119 }
120
121}
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:55
Botan::Output_Buffers::message_count
Pipe::message_id message_count() const
Definition: out_buf.cpp:108
Botan::Output_Buffers::Output_Buffers
Output_Buffers()
Definition: out_buf.cpp:116
Botan::Output_Buffers::get_bytes_read
size_t get_bytes_read(Pipe::message_id) const
Definition: out_buf.cpp:53
Botan::Output_Buffers::add
void add(class SecureQueue *)
Definition: out_buf.cpp:64
Botan::Output_Buffers::remaining
size_t remaining(Pipe::message_id) const
Definition: out_buf.cpp:42
Botan::Output_Buffers::peek
size_t peek(uint8_t[], size_t, size_t, Pipe::message_id) const
Definition: out_buf.cpp:29
Botan::Output_Buffers::retire
void retire()
Definition: out_buf.cpp:77
Botan::Output_Buffers::read
size_t read(uint8_t[], size_t, Pipe::message_id)
Definition: out_buf.cpp:17
Botan::Pipe::message_id
size_t message_id
Definition: pipe.h:35
Botan::SecureQueue
Definition: secqueue.h:23
Botan::SecureQueue::read
size_t read(uint8_t[], size_t) override
Definition: secqueue.cpp:144
Botan::SecureQueue::get_bytes_read
size_t get_bytes_read() const override
Definition: secqueue.cpp:198
Botan::SecureQueue::peek
size_t peek(uint8_t[], size_t, size_t=0) const override
Definition: secqueue.cpp:167
Botan::SecureQueue::size
size_t size() const
Definition: secqueue.cpp:206
Botan
Definition: alg_id.cpp:13