Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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(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 delete m_buffers[i];
83 m_buffers[i] = nullptr;
84 }
85
86 while(m_buffers.size() && !m_buffers[0])
87 {
88 m_buffers.pop_front();
89 m_offset = m_offset + Pipe::message_id(1);
90 }
91 }
92
93 /*
94 * Get a particular output queue
95 */
96 SecureQueue* Output_Buffers::get(Pipe::message_id msg) const
97 {
98 if(msg < m_offset)
99 return nullptr;
100
101 BOTAN_ASSERT(msg < message_count(), "Message number is in range");
102
103 return m_buffers[msg-m_offset];
104 }
105
106 /*
107 * Return the total number of messages
108 */
109 Pipe::message_id Output_Buffers::message_count() const
110 {
111 return (m_offset + m_buffers.size());
112 }
113
114 /*
115 * Output_Buffers Constructor
116 */
117 Output_Buffers::Output_Buffers()
118 {
119 m_offset = 0;
120 }
121
122 /*
123 * Output_Buffers Destructor
124 */
125 Output_Buffers::~Output_Buffers()
126 {
127 for(size_t j = 0; j != m_buffers.size(); ++j)
128 delete m_buffers[j];
129 }
130
131 }
Botan::SecureQueue::read
size_t read(uint8_t[], size_t) override
Definition: secqueue.cpp:141
Botan::SecureQueue
Definition: secqueue.h:20
Botan::Pipe::message_id
size_t message_id
Definition: pipe.h:33
Botan::Output_Buffers::~Output_Buffers
~Output_Buffers()
Definition: out_buf.cpp:125
Botan::Output_Buffers::retire
void retire()
Definition: out_buf.cpp:77
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
Botan::Output_Buffers::peek
size_t peek(uint8_t[], size_t, size_t, Pipe::message_id) const
Definition: out_buf.cpp:29
Botan::SecureQueue::peek
size_t peek(uint8_t[], size_t, size_t=0) const override
Definition: secqueue.cpp:164
Botan::SecureQueue::get_bytes_read
size_t get_bytes_read() const override
Definition: secqueue.cpp:195
Botan::Output_Buffers::Output_Buffers
Output_Buffers()
Definition: out_buf.cpp:117
Botan
Definition: alg_id.cpp:13
Botan::Output_Buffers::remaining
size_t remaining(Pipe::message_id) const
Definition: out_buf.cpp:42
Botan::Output_Buffers::get_bytes_read
size_t get_bytes_read(Pipe::message_id) const
Definition: out_buf.cpp:53
Botan::SecureQueue::size
size_t size() const
Definition: secqueue.cpp:203
Botan::Output_Buffers::add
void add(class SecureQueue *)
Definition: out_buf.cpp:64
Botan::Output_Buffers::read
size_t read(uint8_t[], size_t, Pipe::message_id)
Definition: out_buf.cpp:17
Botan::Output_Buffers::message_count
Pipe::message_id message_count() const
Definition: out_buf.cpp:109