aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/exceptn.h8
-rw-r--r--include/out_buf.h13
-rw-r--r--include/pipe.h8
-rw-r--r--src/exceptn.cpp10
-rw-r--r--src/out_buf.cpp16
-rw-r--r--src/pipe.cpp20
6 files changed, 40 insertions, 35 deletions
diff --git a/include/exceptn.h b/include/exceptn.h
index 1381782cf..5b0106105 100644
--- a/include/exceptn.h
+++ b/include/exceptn.h
@@ -60,14 +60,6 @@ struct Invalid_IV_Length : public Invalid_Argument
};
/*************************************************
-* Invalid_Message_Number Exception *
-*************************************************/
-struct Invalid_Message_Number : public Invalid_Argument
- {
- Invalid_Message_Number(const std::string&, u32bit);
- };
-
-/*************************************************
* Invalid_State Exception *
*************************************************/
struct Invalid_State : public Exception
diff --git a/include/out_buf.h b/include/out_buf.h
index 8965e3895..1e169b9bc 100644
--- a/include/out_buf.h
+++ b/include/out_buf.h
@@ -7,6 +7,7 @@
#define BOTAN_OUTPUT_BUFFER_H__
#include <botan/types.h>
+#include <botan/pipe.h>
#include <deque>
namespace Botan {
@@ -17,22 +18,22 @@ namespace Botan {
class Output_Buffers
{
public:
- u32bit read(byte[], u32bit, u32bit);
- u32bit peek(byte[], u32bit, u32bit, u32bit) const;
- u32bit remaining(u32bit) const;
+ u32bit read(byte[], u32bit, Pipe::message_id);
+ u32bit peek(byte[], u32bit, u32bit, Pipe::message_id) const;
+ u32bit remaining(Pipe::message_id) const;
void add(class SecureQueue*);
void retire();
- u32bit message_count() const;
+ Pipe::message_id message_count() const;
Output_Buffers();
~Output_Buffers();
private:
- class SecureQueue* get(u32bit) const;
+ class SecureQueue* get(Pipe::message_id) const;
std::deque<SecureQueue*> buffers;
- u32bit offset;
+ Pipe::message_id offset;
};
}
diff --git a/include/pipe.h b/include/pipe.h
index 20fdc6a41..89f1ac4db 100644
--- a/include/pipe.h
+++ b/include/pipe.h
@@ -20,6 +20,12 @@ class Pipe : public DataSource
public:
typedef u32bit message_id;
+ class Invalid_Message_Number : public Invalid_Argument
+ {
+ public:
+ Invalid_Message_Number(const std::string&, message_id);
+ };
+
static const message_id LAST_MESSAGE, DEFAULT_MESSAGE;
void write(const byte[], u32bit);
@@ -48,7 +54,7 @@ class Pipe : public DataSource
message_id default_msg() const { return default_read; }
void set_default_msg(message_id);
- u32bit message_count() const;
+ message_id message_count() const;
bool end_of_data() const;
void start_msg();
diff --git a/src/exceptn.cpp b/src/exceptn.cpp
index 07e6bb419..29357afa5 100644
--- a/src/exceptn.cpp
+++ b/src/exceptn.cpp
@@ -34,16 +34,6 @@ Invalid_IV_Length::Invalid_IV_Length(const std::string& mode, u32bit bad_len)
}
/*************************************************
-* Constructor for Invalid_Message_Number *
-*************************************************/
-Invalid_Message_Number::Invalid_Message_Number(const std::string& where,
- u32bit message_no)
- {
- set_msg("Pipe::" + where + ": Invalid message number " +
- to_string(message_no));
- }
-
-/*************************************************
* Constructor for Algorithm_Not_Found *
*************************************************/
Algorithm_Not_Found::Algorithm_Not_Found(const std::string& name)
diff --git a/src/out_buf.cpp b/src/out_buf.cpp
index 2586d65c2..392592705 100644
--- a/src/out_buf.cpp
+++ b/src/out_buf.cpp
@@ -11,7 +11,8 @@ namespace Botan {
/*************************************************
* Read data from a message *
*************************************************/
-u32bit Output_Buffers::read(byte output[], u32bit length, u32bit msg)
+u32bit Output_Buffers::read(byte output[], u32bit length,
+ Pipe::message_id msg)
{
SecureQueue* q = get(msg);
if(q)
@@ -23,7 +24,8 @@ u32bit Output_Buffers::read(byte output[], u32bit length, u32bit msg)
* Peek at data in a message *
*************************************************/
u32bit Output_Buffers::peek(byte output[], u32bit length,
- u32bit stream_offset, u32bit msg) const
+ u32bit stream_offset,
+ Pipe::message_id msg) const
{
SecureQueue* q = get(msg);
if(q)
@@ -34,7 +36,7 @@ u32bit Output_Buffers::peek(byte output[], u32bit length,
/*************************************************
* Check available bytes in a message *
*************************************************/
-u32bit Output_Buffers::remaining(u32bit msg) const
+u32bit Output_Buffers::remaining(Pipe::message_id msg) const
{
SecureQueue* q = get(msg);
if(q)
@@ -67,7 +69,7 @@ void Output_Buffers::retire()
{
delete buffers[0];
buffers.pop_front();
- ++offset;
+ offset = offset + Pipe::message_id(1);
}
else
break;
@@ -77,7 +79,7 @@ void Output_Buffers::retire()
/*************************************************
* Get a particular output queue *
*************************************************/
-SecureQueue* Output_Buffers::get(u32bit msg) const
+SecureQueue* Output_Buffers::get(Pipe::message_id msg) const
{
if(msg < offset)
return 0;
@@ -90,9 +92,9 @@ SecureQueue* Output_Buffers::get(u32bit msg) const
/*************************************************
* Return the total number of messages *
*************************************************/
-u32bit Output_Buffers::message_count() const
+Pipe::message_id Output_Buffers::message_count() const
{
- return (buffers.size() + offset);
+ return (offset + buffers.size());
}
/*************************************************
diff --git a/src/pipe.cpp b/src/pipe.cpp
index b740e049d..228dc3a22 100644
--- a/src/pipe.cpp
+++ b/src/pipe.cpp
@@ -6,9 +6,20 @@
#include <botan/pipe.h>
#include <botan/out_buf.h>
#include <botan/secqueue.h>
+#include <botan/parsing.h>
namespace Botan {
+/*************************************************
+* Constructor for Invalid_Message_Number *
+*************************************************/
+Pipe::Invalid_Message_Number::Invalid_Message_Number(const std::string& where,
+ message_id msg)
+ {
+ set_msg("Pipe::" + where + ": Invalid message number " +
+ to_string(msg));
+ }
+
namespace {
/*************************************************
@@ -276,7 +287,7 @@ void Pipe::pop()
/*************************************************
* Return the number of messages in this Pipe *
*************************************************/
-u32bit Pipe::message_count() const
+Pipe::message_id Pipe::message_count() const
{
return outputs->message_count();
}
@@ -284,7 +295,10 @@ u32bit Pipe::message_count() const
/*************************************************
* Static Member Variables *
*************************************************/
-const Pipe::message_id Pipe::LAST_MESSAGE = static_cast<Pipe::message_id>(-2);
-const Pipe::message_id Pipe::DEFAULT_MESSAGE = static_cast<Pipe::message_id>(-1);
+const Pipe::message_id Pipe::LAST_MESSAGE =
+ static_cast<Pipe::message_id>(-2);
+
+const Pipe::message_id Pipe::DEFAULT_MESSAGE =
+ static_cast<Pipe::message_id>(-1);
}