Security Scol plugin
mqueue.h
Go to the documentation of this file.
1// mqueue.h - originally written and placed in the public domain by Wei Dai
2
5
6#ifndef CRYPTOPP_MQUEUE_H
7#define CRYPTOPP_MQUEUE_H
8
9#include "cryptlib.h"
10#include "queue.h"
11#include "filters.h"
12#include "misc.h"
13
14#include <deque>
15
16NAMESPACE_BEGIN(CryptoPP)
17
18
24{
25public:
26 virtual ~MessageQueue() {}
27
30 MessageQueue(unsigned int nodeSize=256);
31
32 // BufferedTransformation
33 void IsolatedInitialize(const NameValuePairs &parameters)
34 {m_queue.IsolatedInitialize(parameters); m_lengths.assign(1, 0U); m_messageCounts.assign(1, 0U);}
35 size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
36 {
37 CRYPTOPP_UNUSED(blocking);
38 m_queue.Put(begin, length);
39 m_lengths.back() += length;
40 if (messageEnd)
41 {
42 m_lengths.push_back(0);
43 m_messageCounts.back()++;
44 }
45 return 0;
46 }
47 bool IsolatedFlush(bool hardFlush, bool blocking)
48 {CRYPTOPP_UNUSED(hardFlush), CRYPTOPP_UNUSED(blocking); return false;}
49 bool IsolatedMessageSeriesEnd(bool blocking)
50 {CRYPTOPP_UNUSED(blocking); m_messageCounts.push_back(0); return false;}
51
53 {return m_lengths.front();}
54 bool AnyRetrievable() const
55 {return m_lengths.front() > 0;}
56
57 size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
58 size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
59
61 {return m_queue.MaxRetrievable();}
62 unsigned int NumberOfMessages() const
63 {return (unsigned int)m_lengths.size()-1;}
64 bool GetNextMessage();
65
66 unsigned int NumberOfMessagesInThisSeries() const
67 {return m_messageCounts[0];}
68 unsigned int NumberOfMessageSeries() const
69 {return (unsigned int)m_messageCounts.size()-1;}
70
76 unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const;
77
84 const byte * Spy(size_t &contiguousSize) const;
85
88 void swap(MessageQueue &rhs);
89
90private:
91 ByteQueue m_queue;
92 std::deque<lword> m_lengths;
93 std::deque<unsigned int> m_messageCounts;
94};
95
97class CRYPTOPP_DLL EqualityComparisonFilter : public Unflushable<Multichannel<Filter> >
98{
99public:
102 {
104 MismatchDetected() : Exception(DATA_INTEGRITY_CHECK_FAILED, "EqualityComparisonFilter: did not receive the same data on two channels") {}
105 };
106
115 EqualityComparisonFilter(BufferedTransformation *attachment=NULLPTR, bool throwIfNotEqual=true, const std::string &firstChannel="0", const std::string &secondChannel="1")
116 : m_throwIfNotEqual(throwIfNotEqual), m_mismatchDetected(false)
117 , m_firstChannel(firstChannel), m_secondChannel(secondChannel)
118 {Detach(attachment);}
119
120 // BufferedTransformation
121 size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
122 bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
123
124protected:
125 unsigned int MapChannel(const std::string &channel) const;
126 bool HandleMismatchDetected(bool blocking);
127
128private:
129 bool m_throwIfNotEqual, m_mismatchDetected;
130 std::string m_firstChannel, m_secondChannel;
131 MessageQueue m_q[2];
132};
133
134NAMESPACE_END
135
136#ifndef __BORLANDC__
137NAMESPACE_BEGIN(std)
138template<> inline void swap(CryptoPP::MessageQueue &a, CryptoPP::MessageQueue &b)
139{
140 a.swap(b);
141}
142NAMESPACE_END
143#endif
144
145#endif
Provides auto signaling support.
Definition simple.h:423
Interface for buffered transformations.
Definition cryptlib.h:1652
Data structure used to store byte strings.
Definition queue.h:23
Filter that checks messages on two channels for equality.
Definition mqueue.h:98
EqualityComparisonFilter(BufferedTransformation *attachment=NULLPTR, bool throwIfNotEqual=true, const std::string &firstChannel="0", const std::string &secondChannel="1")
Construct an EqualityComparisonFilter.
Definition mqueue.h:115
Base class for all exceptions thrown by the library.
Definition cryptlib.h:159
Data structure used to store messages.
Definition mqueue.h:24
bool AnyRetrievable() const
Determines whether bytes are ready for retrieval.
Definition mqueue.h:54
unsigned int NumberOfMessageSeries() const
Provides the number of messages in a series.
Definition mqueue.h:68
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition mqueue.h:33
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition mqueue.h:35
bool IsolatedMessageSeriesEnd(bool blocking)
Marks the end of a series of messages, without signal propagation.
Definition mqueue.h:49
unsigned int NumberOfMessages() const
Provides the number of meesages processed by this object.
Definition mqueue.h:62
unsigned int NumberOfMessagesInThisSeries() const
Provides the number of messages in a series.
Definition mqueue.h:66
lword TotalBytesRetrievable() const
Provides the number of bytes ready for retrieval.
Definition mqueue.h:60
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
Definition mqueue.h:47
lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
Definition mqueue.h:52
Interface for retrieving values given their names.
Definition cryptlib.h:322
Base class for unflushable filters.
Definition simple.h:134
const lword LWORD_MAX
Large word type max value.
Definition config_int.h:164
word64 lword
Large word type.
Definition config_int.h:158
Abstract base classes that provide a uniform interface to this library.
Implementation of BufferedTransformation's attachment interface.
Utility functions for the Crypto++ library.
Classes for an unlimited queue to store bytes.
Different messages were detected.
Definition mqueue.h:102
MismatchDetected()
Construct a MismatchDetected exception.
Definition mqueue.h:104