6 #ifndef CRYPTOPP_SIMPLE_H
7 #define CRYPTOPP_SIMPLE_H
12 NAMESPACE_BEGIN(CryptoPP)
15 template <class DERIVED, class BASE>
19 Clonable * Clone()
const {
return new DERIVED(*static_cast<const DERIVED *>(
this));}
23 template <
class BASE,
class ALGORITHM_INFO=BASE>
27 static std::string CRYPTOPP_API StaticAlgorithmName() {
return ALGORITHM_INFO::StaticAlgorithmName();}
28 std::string AlgorithmName()
const {
return ALGORITHM_INFO::StaticAlgorithmName();}
35 explicit InvalidKeyLength(
const std::string &algorithm,
size_t length) :
InvalidArgument(algorithm +
": " + IntToString(length) +
" is not a valid key length") {}
42 explicit InvalidRounds(
const std::string &algorithm,
unsigned int rounds) :
InvalidArgument(algorithm +
": " + IntToString(rounds) +
" is not a valid number of rounds") {}
52 bool IsolatedFlush(
bool hardFlush,
bool blocking) {
return false;}
60 bool Flush(
bool completeFlush,
int propagation=-1,
bool blocking=
true)
61 {
return ChannelFlush(
DEFAULT_CHANNEL, completeFlush, propagation, blocking);}
62 bool IsolatedFlush(
bool hardFlush,
bool blocking)
63 {assert(
false);
return false;}
64 bool ChannelFlush(
const std::string &channel,
bool hardFlush,
int propagation=-1,
bool blocking=
true)
66 if (hardFlush && !InputBufferIsEmpty())
67 throw CannotFlush(
"Unflushable<T>: this object has buffered input that cannot be flushed");
71 return attached && propagation ? attached->ChannelFlush(channel, hardFlush, propagation-1, blocking) :
false;
76 virtual bool InputBufferIsEmpty()
const {
return false;}
88 size_t Put2(
const byte *begin,
size_t length,
int messageEnd,
bool blocking)
90 bool IsolatedFlush(
bool,
bool) {
return false;}
91 bool IsolatedMessageSeriesEnd(
bool) {
throw InputRejected();}
93 size_t ChannelPut2(
const std::string &channel,
const byte *begin,
size_t length,
int messageEnd,
bool blocking)
94 {
throw InputRejected();}
95 bool ChannelMessageSeriesEnd(
const std::string &,
int,
bool) {
throw InputRejected();}
103 virtual bool Flush(
bool hardFlush,
int propagation=-1,
bool blocking=
true) =0;
106 bool IsolatedFlush(
bool hardFlush,
bool blocking) {assert(
false);
return false;}
117 void IsolatedInitialize(
const NameValuePairs ¶meters) {assert(
false);}
125 bool Flush(
bool hardFlush,
int propagation=-1,
bool blocking=
true)
126 {
return this->ChannelFlush(
DEFAULT_CHANNEL, hardFlush, propagation, blocking);}
127 bool MessageSeriesEnd(
int propagation=-1,
bool blocking=
true)
128 {
return this->ChannelMessageSeriesEnd(
DEFAULT_CHANNEL, propagation, blocking);}
129 byte * CreatePutSpace(
size_t &size)
131 size_t Put2(
const byte *begin,
size_t length,
int messageEnd,
bool blocking)
132 {
return this->ChannelPut2(
DEFAULT_CHANNEL, begin, length, messageEnd, blocking);}
133 size_t PutModifiable2(byte *inString,
size_t length,
int messageEnd,
bool blocking)
134 {
return this->ChannelPutModifiable2(
DEFAULT_CHANNEL, inString, length, messageEnd, blocking);}
138 byte * ChannelCreatePutSpace(
const std::string &channel,
size_t &size)
139 {size = 0;
return NULL;}
140 bool ChannelPutModifiable(
const std::string &channel, byte *inString,
size_t length)
141 {this->ChannelPut(channel, inString, length);
return false;}
143 virtual size_t ChannelPut2(
const std::string &channel,
const byte *begin,
size_t length,
int messageEnd,
bool blocking) =0;
144 size_t ChannelPutModifiable2(
const std::string &channel, byte *begin,
size_t length,
int messageEnd,
bool blocking)
145 {
return ChannelPut2(channel, begin, length, messageEnd, blocking);}
147 virtual bool ChannelFlush(
const std::string &channel,
bool hardFlush,
int propagation=-1,
bool blocking=
true) =0;
155 AutoSignaling(
int propagation=-1) : m_autoSignalPropagation(propagation) {}
157 void SetAutoSignalPropagation(
int propagation)
158 {m_autoSignalPropagation = propagation;}
159 int GetAutoSignalPropagation()
const
160 {
return m_autoSignalPropagation;}
163 int m_autoSignalPropagation;
167 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE
Store :
public AutoSignaling<InputRejecting<BufferedTransformation> >
170 Store() : m_messageEnd(
false) {}
174 m_messageEnd =
false;
175 StoreInitialize(parameters);
179 bool GetNextMessage();
183 virtual void StoreInitialize(
const NameValuePairs ¶meters) =0;
193 {transferBytes = 0;
return 0;}
203 size_t Put2(
const byte *begin,
size_t length,
int messageEnd,
bool blocking)
exception thrown when an invalid argument is detected
exception thrown by a class when Flush(true) is called but it can't completely flush its buffers ...
std::string AlgorithmName() const
returns name of this algorithm, not universally implemented yet
A BufferedTransformation that only contains pre-existing data as "output".
interface for cloning objects, this is not implemented by most classes yet
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
input multiple bytes for blocking or non-blocking processing
exception thrown by a class if a non-implemented method is called
const std::string DEFAULT_CHANNEL
the default channel for BufferedTransformation, equal to the empty string
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
upon return, byteCount contains number of bytes that have finished being transfered, and returns the number of bytes left in the current transfer block
const NameValuePairs & g_nullNameValuePairs
empty set of name-value pairs
size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
upon return, begin contains the start position of data yet to be finished copying, and returns the number of bytes left in the current transfer block
A BufferedTransformation that doesn't produce any retrievable output.
unsigned int NumberOfMessages() const
number of times MessageEnd() has been received minus messages retrieved or skipped ...
interface for retrieving values given their names