#include "botan-1.6/include/out_buf.h"
#include "botan-1.6/include/secqueue.h"
namespace Enctain {
namespace Botan {
u32bit Output_Buffers::read(byte output[], u32bit length, u32bit msg)
{
SecureQueue* q = get(msg);
if(q)
return q->read(output, length);
return 0;
}
u32bit Output_Buffers::peek(byte output[], u32bit length,
u32bit stream_offset, u32bit msg) const
{
SecureQueue* q = get(msg);
if(q)
return q->peek(output, length, stream_offset);
return 0;
}
u32bit Output_Buffers::remaining(u32bit msg) const
{
SecureQueue* q = get(msg);
if(q)
return q->size();
return 0;
}
void Output_Buffers::add(SecureQueue* queue)
{
if(!queue)
throw Internal_Error("Output_Buffers::add: Argument was NULL");
if(buffers.size() == buffers.max_size())
throw Internal_Error("Output_Buffers::add: No more room in container");
buffers.push_back(queue);
}
void Output_Buffers::retire()
{
while(buffers.size())
{
if(buffers[0] == 0 || buffers[0]->size() == 0)
{
delete buffers[0];
buffers.pop_front();
++offset;
}
else
break;
}
}
SecureQueue* Output_Buffers::get(u32bit msg) const
{
if(msg < offset)
return 0;
if(msg > message_count())
throw Internal_Error("Output_Buffers::get: msg > size");
return buffers[msg-offset];
}
u32bit Output_Buffers::message_count() const
{
return (buffers.size() + offset);
}
Output_Buffers::Output_Buffers()
{
offset = 0;
}
Output_Buffers::~Output_Buffers()
{
for(u32bit j = 0; j != buffers.size(); ++j)
delete buffers[j];
}
}
}