Crypto++ 8.7
Free C++ class library of cryptographic schemes
simple.h
Go to the documentation of this file.
1// simple.h - originally written and placed in the public domain by Wei Dai
2
3/// \file simple.h
4/// \brief Classes providing basic library services.
5
6#ifndef CRYPTOPP_SIMPLE_H
7#define CRYPTOPP_SIMPLE_H
8
9#include "config.h"
10
11#if CRYPTOPP_MSC_VERSION
12# pragma warning(push)
13# pragma warning(disable: 4127 4189)
14#endif
15
16#include "cryptlib.h"
17#include "misc.h"
18
19NAMESPACE_BEGIN(CryptoPP)
20
21/// \brief Base class for identifying algorithm
22/// \tparam BASE base class from which to derive
23/// \tparam DERIVED class which to clone
24template <class DERIVED, class BASE>
25class CRYPTOPP_NO_VTABLE ClonableImpl : public BASE
26{
27public:
28 /// \brief Create a copy of this object
29 /// \return a copy of this object
30 /// \details The caller is responsible for freeing the object.
31 Clonable * Clone() const {return new DERIVED(*static_cast<const DERIVED *>(this));}
32};
33
34/// \brief Base class information
35/// \tparam BASE an Algorithm derived class
36/// \tparam ALGORITHM_INFO an Algorithm derived class
37/// \details AlgorithmImpl provides StaticAlgorithmName from the template parameter BASE
38template <class BASE, class ALGORITHM_INFO=BASE>
39class CRYPTOPP_NO_VTABLE AlgorithmImpl : public BASE
40{
41public:
42 /// \brief The algorithm name
43 /// \return the algorithm name
44 /// \details StaticAlgorithmName returns the algorithm's name as a static member function.
45 /// The name is taken from information provided by BASE.
46 static std::string CRYPTOPP_API StaticAlgorithmName() {return ALGORITHM_INFO::StaticAlgorithmName();}
47 /// \brief The algorithm name
48 /// \return the algorithm name
49 /// \details AlgorithmName returns the algorithm's name as a member function.
50 /// The name is acquired by calling StaticAlgorithmName.
51 std::string AlgorithmName() const {return ALGORITHM_INFO::StaticAlgorithmName();}
52};
53
54/// \brief Exception thrown when an invalid key length is encountered
55class CRYPTOPP_DLL InvalidKeyLength : public InvalidArgument
56{
57public:
58 /// \brief Construct an InvalidKeyLength
59 /// \param algorithm the Algorithm associated with the exception
60 /// \param length the key size associated with the exception
61 explicit InvalidKeyLength(const std::string &algorithm, size_t length) : InvalidArgument(algorithm + ": " + IntToString(length) + " is not a valid key length") {}
62};
63
64/// \brief Exception thrown when an invalid number of rounds is encountered
65class CRYPTOPP_DLL InvalidRounds : public InvalidArgument
66{
67public:
68 /// \brief Construct an InvalidRounds
69 /// \param algorithm the Algorithm associated with the exception
70 /// \param rounds the number of rounds associated with the exception
71 explicit InvalidRounds(const std::string &algorithm, unsigned int rounds) : InvalidArgument(algorithm + ": " + IntToString(rounds) + " is not a valid number of rounds") {}
72};
73
74/// \brief Exception thrown when an invalid block size is encountered
75class CRYPTOPP_DLL InvalidBlockSize : public InvalidArgument
76{
77public:
78 /// \brief Construct an InvalidBlockSize
79 /// \param algorithm the Algorithm associated with the exception
80 /// \param length the block size associated with the exception
81 explicit InvalidBlockSize(const std::string &algorithm, size_t length) : InvalidArgument(algorithm + ": " + IntToString(length) + " is not a valid block size") {}
82};
83
84/// \brief Exception thrown when an invalid derived key length is encountered
85class CRYPTOPP_DLL InvalidDerivedKeyLength : public InvalidArgument
86{
87public:
88 /// \brief Construct an InvalidDerivedKeyLength
89 /// \param algorithm the Algorithm associated with the exception
90 /// \param length the size associated with the exception
91 explicit InvalidDerivedKeyLength(const std::string &algorithm, size_t length) : InvalidArgument(algorithm + ": " + IntToString(length) + " is not a valid derived key length") {}
92};
93
94/// \brief Exception thrown when an invalid personalization string length is encountered
96{
97public:
98 /// \brief Construct an InvalidPersonalizationLength
99 /// \param algorithm the Algorithm associated with the exception
100 /// \param length the personalization size associated with the exception
101 explicit InvalidPersonalizationLength(const std::string &algorithm, size_t length) : InvalidArgument(algorithm + ": " + IntToString(length) + " is not a valid salt length") {}
102};
103
104/// \brief Exception thrown when an invalid salt length is encountered
105class CRYPTOPP_DLL InvalidSaltLength : public InvalidArgument
106{
107public:
108 /// \brief Construct an InvalidSaltLength
109 /// \param algorithm the Algorithm associated with the exception
110 /// \param length the salt size associated with the exception
111 explicit InvalidSaltLength(const std::string &algorithm, size_t length) : InvalidArgument(algorithm + ": " + IntToString(length) + " is not a valid salt length") {}
112};
113
114// *****************************
115
116/// \brief Base class for bufferless filters
117/// \tparam T the class or type
118template <class T>
119class CRYPTOPP_NO_VTABLE Bufferless : public T
120{
121public:
122 /// \brief Flushes data buffered by this object, without signal propagation
123 /// \param hardFlush indicates whether all data should be flushed
124 /// \param blocking specifies whether the object should block when processing input
125 /// \note hardFlush must be used with care
126 bool IsolatedFlush(bool hardFlush, bool blocking)
127 {CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); return false;}
128};
129
130/// \brief Base class for unflushable filters
131/// \tparam T the class or type
132template <class T>
133class CRYPTOPP_NO_VTABLE Unflushable : public T
134{
135public:
136 /// \brief Flush buffered input and/or output, with signal propagation
137 /// \param completeFlush is used to indicate whether all data should be flushed
138 /// \param propagation the number of attached transformations the Flush()
139 /// signal should be passed
140 /// \param blocking specifies whether the object should block when processing
141 /// input
142 /// \details propagation count includes this object. Setting propagation to
143 /// <tt>1</tt> means this object only. Setting propagation to <tt>-1</tt>
144 /// means unlimited propagation.
145 /// \note Hard flushes must be used with care. It means try to process and
146 /// output everything, even if there may not be enough data to complete the
147 /// action. For example, hard flushing a HexDecoder would cause an error if
148 /// you do it after inputing an odd number of hex encoded characters.
149 /// \note For some types of filters, like ZlibDecompressor, hard flushes can
150 /// only be done at "synchronization points". These synchronization points
151 /// are positions in the data stream that are created by hard flushes on the
152 /// corresponding reverse filters, in this example ZlibCompressor. This is
153 /// useful when zlib compressed data is moved across a network in packets
154 /// and compression state is preserved across packets, as in the SSH2 protocol.
155 bool Flush(bool completeFlush, int propagation=-1, bool blocking=true)
156 {return ChannelFlush(DEFAULT_CHANNEL, completeFlush, propagation, blocking);}
157
158 /// \brief Flushes data buffered by this object, without signal propagation
159 /// \param hardFlush indicates whether all data should be flushed
160 /// \param blocking specifies whether the object should block when processing input
161 /// \note hardFlush must be used with care
162 bool IsolatedFlush(bool hardFlush, bool blocking)
163 {CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); CRYPTOPP_ASSERT(false); return false;}
164
165 /// \brief Flush buffered input and/or output on a channel
166 /// \param channel the channel to flush the data
167 /// \param hardFlush is used to indicate whether all data should be flushed
168 /// \param propagation the number of attached transformations the ChannelFlush()
169 /// signal should be passed
170 /// \param blocking specifies whether the object should block when processing input
171 /// \return true of the Flush was successful
172 /// \details propagation count includes this object. Setting propagation to
173 /// <tt>1</tt> means this object only. Setting propagation to <tt>-1</tt> means
174 /// unlimited propagation.
175 bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
176 {
177 if (hardFlush && !InputBufferIsEmpty())
178 throw CannotFlush("Unflushable<T>: this object has buffered input that cannot be flushed");
179 else
180 {
181 BufferedTransformation *attached = this->AttachedTransformation();
182 return attached && propagation ? attached->ChannelFlush(channel, hardFlush, propagation-1, blocking) : false;
183 }
184 }
185
186protected:
187 virtual bool InputBufferIsEmpty() const {return false;}
188};
189
190/// \brief Base class for input rejecting filters
191/// \tparam T the class or type
192/// \details T should be a BufferedTransformation derived class
193template <class T>
194class CRYPTOPP_NO_VTABLE InputRejecting : public T
195{
196public:
198 {InputRejected() : NotImplemented("BufferedTransformation: this object doesn't allow input") {}};
199
200 /// \name INPUT
201 //@{
202
203 /// \brief Input a byte array for processing
204 /// \param inString the byte array to process
205 /// \param length the size of the string, in bytes
206 /// \param messageEnd means how many filters to signal MessageEnd() to, including this one
207 /// \param blocking specifies whether the object should block when processing input
208 /// \throw InputRejected
209 /// \return the number of bytes that remain to be processed (i.e., bytes not processed)
210 /// \details Internally, the default implementation throws InputRejected.
211 size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
212 {CRYPTOPP_UNUSED(inString); CRYPTOPP_UNUSED(length); CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking); throw InputRejected();}
213 //@}
214
215 /// \name SIGNALS
216 //@{
217
218 /// \brief Flushes data buffered by this object, without signal propagation
219 /// \param hardFlush indicates whether all data should be flushed
220 /// \param blocking specifies whether the object should block when processing input
221 /// \note hardFlush must be used with care
222 bool IsolatedFlush(bool hardFlush, bool blocking)
223 {CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); return false;}
224
225 /// \brief Marks the end of a series of messages, without signal propagation
226 /// \param blocking specifies whether the object should block when completing the processing on
227 /// the current series of messages
228 /// \return true if the message was successful, false otherwise
229 bool IsolatedMessageSeriesEnd(bool blocking)
230 {CRYPTOPP_UNUSED(blocking); throw InputRejected();}
231
232 /// \brief Input multiple bytes for processing on a channel.
233 /// \param channel the channel to process the data.
234 /// \param inString the byte buffer to process.
235 /// \param length the size of the string, in bytes.
236 /// \param messageEnd means how many filters to signal MessageEnd() to, including this one.
237 /// \param blocking specifies whether the object should block when processing input.
238 /// \return the number of bytes that remain to be processed (i.e., bytes not processed)
239 size_t ChannelPut2(const std::string &channel, const byte *inString, size_t length, int messageEnd, bool blocking)
240 {CRYPTOPP_UNUSED(channel); CRYPTOPP_UNUSED(inString); CRYPTOPP_UNUSED(length);
241 CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking); throw InputRejected();}
242
243 /// \brief Marks the end of a series of messages on a channel
244 /// \param channel the channel to signal the end of a series of messages
245 /// \param messageEnd the number of attached transformations the ChannelMessageSeriesEnd() signal should be passed
246 /// \param blocking specifies whether the object should block when processing input
247 /// \return true if the message was successful, false otherwise
248 /// \details Each object that receives the signal will perform its processing, decrement
249 /// propagation, and then pass the signal on to attached transformations if the value is not 0.
250 /// \details propagation count includes this object. Setting propagation to <tt>1</tt> means this
251 /// object only. Setting propagation to <tt>-1</tt> means unlimited propagation.
252 /// \note There should be a MessageEnd() immediately before MessageSeriesEnd().
253 bool ChannelMessageSeriesEnd(const std::string& channel, int messageEnd, bool blocking)
254 {CRYPTOPP_UNUSED(channel); CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking); throw InputRejected();}
255 //@}
256};
257
258/// \brief Interface for custom flush signals propagation
259/// \tparam T BufferedTransformation derived class
260template <class T>
261class CRYPTOPP_NO_VTABLE CustomFlushPropagation : public T
262{
263public:
264 /// \name SIGNALS
265 //@{
266
267 /// \brief Flush buffered input and/or output, with signal propagation
268 /// \param hardFlush is used to indicate whether all data should be flushed
269 /// \param propagation the number of attached transformations the Flush() signal should be passed
270 /// \param blocking specifies whether the object should block when processing input
271 /// \details propagation count includes this object. Setting propagation to <tt>1</tt> means this
272 /// object only. Setting propagation to <tt>-1</tt> means unlimited propagation.
273 /// \note Hard flushes must be used with care. It means try to process and output everything, even if
274 /// there may not be enough data to complete the action. For example, hard flushing a HexDecoder
275 /// would cause an error if you do it after inputing an odd number of hex encoded characters.
276 /// \note For some types of filters, like ZlibDecompressor, hard flushes can only
277 /// be done at "synchronization points". These synchronization points are positions in the data
278 /// stream that are created by hard flushes on the corresponding reverse filters, in this
279 /// example ZlibCompressor. This is useful when zlib compressed data is moved across a
280 /// network in packets and compression state is preserved across packets, as in the SSH2 protocol.
281 virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true) =0;
282
283 //@}
284
285private:
286 bool IsolatedFlush(bool hardFlush, bool blocking)
287 {CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); CRYPTOPP_ASSERT(false); return false;}
288};
289
290/// \brief Interface for custom flush signals
291/// \tparam T BufferedTransformation derived class
292template <class T>
293class CRYPTOPP_NO_VTABLE CustomSignalPropagation : public CustomFlushPropagation<T>
294{
295public:
296 /// \brief Initialize or reinitialize this object, with signal propagation
297 /// \param parameters a set of NameValuePairs to initialize or reinitialize this object
298 /// \param propagation the number of attached transformations the Initialize() signal should be passed
299 /// \details Initialize() is used to initialize or reinitialize an object using a variable number of
300 /// arbitrarily typed arguments. The function avoids the need for multiple constructors providing
301 /// all possible combintations of configurable parameters.
302 /// \details propagation count includes this object. Setting propagation to <tt>1</tt> means this
303 /// object only. Setting propagation to <tt>-1</tt> means unlimited propagation.
304 virtual void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1) =0;
305
306private:
307 void IsolatedInitialize(const NameValuePairs &parameters)
308 {CRYPTOPP_UNUSED(parameters); CRYPTOPP_ASSERT(false);}
309};
310
311/// \brief Multiple channels support for custom signal processing
312/// \tparam T the class or type
313/// \details T should be a BufferedTransformation derived class
314template <class T>
315class CRYPTOPP_NO_VTABLE Multichannel : public CustomFlushPropagation<T>
316{
317public:
318 bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
319 {return this->ChannelFlush(DEFAULT_CHANNEL, hardFlush, propagation, blocking);}
320
321 /// \brief Marks the end of a series of messages, with signal propagation
322 /// \param propagation the number of attached transformations the MessageSeriesEnd() signal should be passed
323 /// \param blocking specifies whether the object should block when processing input
324 /// \details Each object that receives the signal will perform its processing, decrement
325 /// propagation, and then pass the signal on to attached transformations if the value is not 0.
326 /// \details propagation count includes this object. Setting propagation to <tt>1</tt> means this
327 /// object only. Setting propagation to <tt>-1</tt> means unlimited propagation.
328 /// \note There should be a MessageEnd() immediately before MessageSeriesEnd().
329 bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
330 {return this->ChannelMessageSeriesEnd(DEFAULT_CHANNEL, propagation, blocking);}
331
332 /// \brief Request space which can be written into by the caller
333 /// \param size the requested size of the buffer
334 /// \details The purpose of this method is to help avoid extra memory allocations.
335 /// \details size is an \a IN and \a OUT parameter and used as a hint. When the call is made,
336 /// size is the requested size of the buffer. When the call returns, size is the size of
337 /// the array returned to the caller.
338 /// \details The base class implementation sets size to 0 and returns NULL.
339 /// \note Some objects, like ArraySink, cannot create a space because its fixed. In the case of
340 /// an ArraySink, the pointer to the array is returned and the size is remaining size.
341 byte * CreatePutSpace(size_t &size)
342 {return this->ChannelCreatePutSpace(DEFAULT_CHANNEL, size);}
343
344 /// \brief Input multiple bytes for processing
345 /// \param inString the byte buffer to process
346 /// \param length the size of the string, in bytes
347 /// \param messageEnd means how many filters to signal MessageEnd() to, including this one
348 /// \param blocking specifies whether the object should block when processing input
349 /// \return the number of bytes that remain to be processed (i.e., bytes not processed)
350 /// \details Derived classes must implement Put2().
351 size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
352 {return this->ChannelPut2(DEFAULT_CHANNEL, inString, length, messageEnd, blocking);}
353
354 /// \brief Input multiple bytes that may be modified by callee.
355 /// \param inString the byte buffer to process.
356 /// \param length the size of the string, in bytes.
357 /// \param messageEnd means how many filters to signal MessageEnd() to, including this one.
358 /// \param blocking specifies whether the object should block when processing input.
359 /// \return the number of bytes that remain to be processed (i.e., bytes not processed)
360 /// \details Internally, PutModifiable2() calls Put2().
361 size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking)
362 {return this->ChannelPutModifiable2(DEFAULT_CHANNEL, inString, length, messageEnd, blocking);}
363
364 // void ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1)
365 // {PropagateMessageSeriesEnd(propagation, channel);}
366
367 /// \brief Request space which can be written into by the caller
368 /// \param channel the channel to process the data
369 /// \param size the requested size of the buffer
370 /// \return a pointer to a memory block with length size
371 /// \details The purpose of this method is to help avoid extra memory allocations.
372 /// \details size is an \a IN and \a OUT parameter and used as a hint. When the call is made,
373 /// size is the requested size of the buffer. When the call returns, size is the size of
374 /// the array returned to the caller.
375 /// \details The base class implementation sets size to 0 and returns NULL.
376 /// \note Some objects, like ArraySink(), cannot create a space because its fixed. In the case of
377 /// an ArraySink(), the pointer to the array is returned and the size is remaining size.
378 byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
379 {CRYPTOPP_UNUSED(channel); size = 0; return NULLPTR;}
380
381 /// \brief Input multiple bytes that may be modified by callee on a channel
382 /// \param channel the channel to process the data.
383 /// \param inString the byte buffer to process
384 /// \param length the size of the string, in bytes
385 /// \return true if all bytes were processed, false otherwise.
386 bool ChannelPutModifiable(const std::string &channel, byte *inString, size_t length)
387 {this->ChannelPut(channel, inString, length); return false;}
388
389 /// \brief Input multiple bytes for processing on a channel.
390 /// \param channel the channel to process the data.
391 /// \param begin the byte buffer to process.
392 /// \param length the size of the string, in bytes.
393 /// \param messageEnd means how many filters to signal MessageEnd() to, including this one.
394 /// \param blocking specifies whether the object should block when processing input.
395 /// \return the number of bytes that remain to be processed (i.e., bytes not processed)
396 virtual size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking) =0;
397
398 /// \brief Input multiple bytes that may be modified by callee on a channel
399 /// \param channel the channel to process the data
400 /// \param begin the byte buffer to process
401 /// \param length the size of the string, in bytes
402 /// \param messageEnd means how many filters to signal MessageEnd() to, including this one
403 /// \param blocking specifies whether the object should block when processing input
404 /// \return the number of bytes that remain to be processed (i.e., bytes not processed)
405 size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
406 {return ChannelPut2(channel, begin, length, messageEnd, blocking);}
407
408 /// \brief Flush buffered input and/or output on a channel
409 /// \param channel the channel to flush the data
410 /// \param hardFlush is used to indicate whether all data should be flushed
411 /// \param propagation the number of attached transformations the ChannelFlush() signal should be passed
412 /// \param blocking specifies whether the object should block when processing input
413 /// \return true of the Flush was successful
414 /// \details propagation count includes this object. Setting propagation to <tt>1</tt> means this
415 /// object only. Setting propagation to <tt>-1</tt> means unlimited propagation.
416 virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true) =0;
417};
418
419/// \brief Provides auto signaling support
420/// \tparam T BufferedTransformation derived class
421template <class T>
422class CRYPTOPP_NO_VTABLE AutoSignaling : public T
423{
424public:
425 /// \brief Construct an AutoSignaling
426 /// \param propagation the propagation count
427 AutoSignaling(int propagation=-1) : m_autoSignalPropagation(propagation) {}
428
429 /// \brief Set propagation of automatically generated and transferred signals
430 /// \param propagation then new value
431 /// \details Setting propagation to <tt>0</tt> means do not automatically generate signals. Setting
432 /// propagation to <tt>-1</tt> means unlimited propagation.
433 void SetAutoSignalPropagation(int propagation)
434 {m_autoSignalPropagation = propagation;}
435
436 /// \brief Retrieve automatic signal propagation value
437 /// \return the number of attached transformations the signal is propagated to. 0 indicates
438 /// the signal is only witnessed by this object
440 {return m_autoSignalPropagation;}
441
442private:
443 int m_autoSignalPropagation;
444};
445
446/// \brief Acts as a Source for pre-existing, static data
447class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Store : public AutoSignaling<InputRejecting<BufferedTransformation> >
448{
449public:
450 /// \brief Construct a Store
451 Store() : m_messageEnd(false) {}
452
453 void IsolatedInitialize(const NameValuePairs &parameters)
454 {
455 m_messageEnd = false;
456 StoreInitialize(parameters);
457 }
458
459 unsigned int NumberOfMessages() const {return m_messageEnd ? 0 : 1;}
461 unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const;
462
463protected:
464 virtual void StoreInitialize(const NameValuePairs &parameters) =0;
465
466 bool m_messageEnd;
467};
468
469/// \brief Implementation of BufferedTransformation's attachment interface
470/// \details Sink is a cornerstone of the Pipeline trinity. Data flows from
471/// Sources, through Filters, and then terminates in Sinks. The difference
472/// between a Source and Filter is a Source \a pumps data, while a Filter does
473/// not. The difference between a Filter and a Sink is a Filter allows an
474/// attached transformation, while a Sink does not.
475/// \details A Sink does not produce any retrievable output.
476/// \details See the discussion of BufferedTransformation in cryptlib.h for
477/// more details.
478class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Sink : public BufferedTransformation
479{
480public:
481 size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
482 {CRYPTOPP_UNUSED(target); CRYPTOPP_UNUSED(transferBytes); CRYPTOPP_UNUSED(channel); CRYPTOPP_UNUSED(blocking); transferBytes = 0; return 0;}
483 size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
484 {CRYPTOPP_UNUSED(target); CRYPTOPP_UNUSED(begin); CRYPTOPP_UNUSED(end); CRYPTOPP_UNUSED(channel); CRYPTOPP_UNUSED(blocking); return 0;}
485};
486
487/// \brief Acts as an input discarding Filter or Sink
488/// \details The BitBucket discards all input and returns 0 to the caller
489/// to indicate all data was processed.
490class CRYPTOPP_DLL BitBucket : public Bufferless<Sink>
491{
492public:
493 std::string AlgorithmName() const {return "BitBucket";}
495 {CRYPTOPP_UNUSED(params);}
496 size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
497 {CRYPTOPP_UNUSED(inString); CRYPTOPP_UNUSED(length); CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking); return 0;}
498};
499
500NAMESPACE_END
501
502#if CRYPTOPP_MSC_VERSION
503# pragma warning(pop)
504#endif
505
506#endif
Base class information.
Definition: simple.h:40
static std::string StaticAlgorithmName()
The algorithm name.
Definition: simple.h:46
std::string AlgorithmName() const
The algorithm name.
Definition: simple.h:51
Provides auto signaling support.
Definition: simple.h:423
int GetAutoSignalPropagation() const
Retrieve automatic signal propagation value.
Definition: simple.h:439
AutoSignaling(int propagation=-1)
Construct an AutoSignaling.
Definition: simple.h:427
void SetAutoSignalPropagation(int propagation)
Set propagation of automatically generated and transferred signals.
Definition: simple.h:433
Acts as an input discarding Filter or Sink.
Definition: simple.h:491
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: simple.h:496
void IsolatedInitialize(const NameValuePairs &params)
Initialize or reinitialize this object, without signal propagation.
Definition: simple.h:494
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: simple.h:493
Interface for buffered transformations.
Definition: cryptlib.h:1652
virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output on a channel.
Base class for bufferless filters.
Definition: simple.h:120
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
Definition: simple.h:126
Flush(true) was called but it can't completely flush its buffers.
Definition: cryptlib.h:243
Interface for cloning objects.
Definition: cryptlib.h:585
Base class for identifying algorithm.
Definition: simple.h:26
Clonable * Clone() const
Create a copy of this object.
Definition: simple.h:31
Interface for custom flush signals propagation.
Definition: simple.h:262
virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)=0
Flush buffered input and/or output, with signal propagation.
Interface for custom flush signals.
Definition: simple.h:294
virtual void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1)=0
Initialize or reinitialize this object, with signal propagation.
Base class for input rejecting filters.
Definition: simple.h:195
bool ChannelMessageSeriesEnd(const std::string &channel, int messageEnd, bool blocking)
Marks the end of a series of messages on a channel.
Definition: simple.h:253
size_t ChannelPut2(const std::string &channel, const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing on a channel.
Definition: simple.h:239
bool IsolatedMessageSeriesEnd(bool blocking)
Marks the end of a series of messages, without signal propagation.
Definition: simple.h:229
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input a byte array for processing.
Definition: simple.h:211
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
Definition: simple.h:222
An invalid argument was detected.
Definition: cryptlib.h:203
Exception thrown when an invalid block size is encountered.
Definition: simple.h:76
InvalidBlockSize(const std::string &algorithm, size_t length)
Construct an InvalidBlockSize.
Definition: simple.h:81
Exception thrown when an invalid derived key length is encountered.
Definition: simple.h:86
InvalidDerivedKeyLength(const std::string &algorithm, size_t length)
Construct an InvalidDerivedKeyLength.
Definition: simple.h:91
Exception thrown when an invalid key length is encountered.
Definition: simple.h:56
InvalidKeyLength(const std::string &algorithm, size_t length)
Construct an InvalidKeyLength.
Definition: simple.h:61
Exception thrown when an invalid personalization string length is encountered.
Definition: simple.h:96
InvalidPersonalizationLength(const std::string &algorithm, size_t length)
Construct an InvalidPersonalizationLength.
Definition: simple.h:101
Exception thrown when an invalid number of rounds is encountered.
Definition: simple.h:66
InvalidRounds(const std::string &algorithm, unsigned int rounds)
Construct an InvalidRounds.
Definition: simple.h:71
Exception thrown when an invalid salt length is encountered.
Definition: simple.h:106
InvalidSaltLength(const std::string &algorithm, size_t length)
Construct an InvalidSaltLength.
Definition: simple.h:111
Multiple channels support for custom signal processing.
Definition: simple.h:316
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: simple.h:341
virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)=0
Flush buffered input and/or output on a channel.
bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
Definition: simple.h:329
size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee on a channel.
Definition: simple.h:405
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: simple.h:351
virtual size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking)=0
Input multiple bytes for processing on a channel.
byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
Definition: simple.h:378
bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: simple.h:318
bool ChannelPutModifiable(const std::string &channel, byte *inString, size_t length)
Input multiple bytes that may be modified by callee on a channel.
Definition: simple.h:386
size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee.
Definition: simple.h:361
Interface for retrieving values given their names.
Definition: cryptlib.h:322
A method was called which was not implemented.
Definition: cryptlib.h:233
Implementation of BufferedTransformation's attachment interface.
Definition: simple.h:479
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer bytes from this object to another BufferedTransformation.
Definition: simple.h:481
size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
Copy bytes from this object to another BufferedTransformation.
Definition: simple.h:483
Acts as a Source for pre-existing, static data.
Definition: simple.h:448
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: simple.h:453
bool GetNextMessage()
Start retrieving the next message.
Store()
Construct a Store.
Definition: simple.h:451
unsigned int NumberOfMessages() const
Provides the number of meesages processed by this object.
Definition: simple.h:459
Base class for unflushable filters.
Definition: simple.h:134
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
Definition: simple.h:162
bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output on a channel.
Definition: simple.h:175
bool Flush(bool completeFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: simple.h:155
Library configuration file.
#define CRYPTOPP_API
Win32 calling convention.
Definition: config_dll.h:119
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.
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Definition: cryptlib.h:511
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
Definition: cryptlib.h:529
Utility functions for the Crypto++ library.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition: misc.h:724
Crypto++ library namespace.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition: trap.h:68