Crypto++ 8.9 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
19 NAMESPACE_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
24 template <class DERIVED, class BASE>
25 class CRYPTOPP_NO_VTABLE ClonableImpl : public BASE
26 {
27 public:
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
38 template <class BASE, class ALGORITHM_INFO=BASE>
39 class CRYPTOPP_NO_VTABLE AlgorithmImpl : public BASE
40 {
41 public:
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
55 class CRYPTOPP_DLL InvalidKeyLength : public InvalidArgument
56 {
57 public:
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
65 class CRYPTOPP_DLL InvalidRounds : public InvalidArgument
66 {
67 public:
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
75 class CRYPTOPP_DLL InvalidBlockSize : public InvalidArgument
76 {
77 public:
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
85 class CRYPTOPP_DLL InvalidDerivedKeyLength : public InvalidArgument
86 {
87 public:
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
95 class CRYPTOPP_DLL InvalidPersonalizationLength : public InvalidArgument
96 {
97 public:
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
105 class CRYPTOPP_DLL InvalidSaltLength : public InvalidArgument
106 {
107 public:
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
118 template <class T>
119 class CRYPTOPP_NO_VTABLE Bufferless : public T
120 {
121 public:
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
132 template <class T>
133 class CRYPTOPP_NO_VTABLE Unflushable : public T
134 {
135 public:
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
186 protected:
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
193 template <class T>
194 class CRYPTOPP_NO_VTABLE InputRejecting : public T
195 {
196 public:
197 struct InputRejected : public NotImplemented
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
260 template <class T>
261 class CRYPTOPP_NO_VTABLE CustomFlushPropagation : public T
262 {
263 public:
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
285 private:
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
292 template <class T>
293 class CRYPTOPP_NO_VTABLE CustomSignalPropagation : public CustomFlushPropagation<T>
294 {
295 public:
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
306 private:
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
314 template <class T>
315 class CRYPTOPP_NO_VTABLE Multichannel : public CustomFlushPropagation<T>
316 {
317 public:
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
421 template <class T>
422 class CRYPTOPP_NO_VTABLE AutoSignaling : public T
423 {
424 public:
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
439 int GetAutoSignalPropagation() const
440 {return m_autoSignalPropagation;}
441
442 private:
443 int m_autoSignalPropagation;
444 };
445
446 /// \brief Acts as a Source for pre-existing, static data
447 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Store : public AutoSignaling<InputRejecting<BufferedTransformation> >
448 {
449 public:
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;}
460 bool GetNextMessage();
461 unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const;
462
463 protected:
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.
478 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Sink : public BufferedTransformation
479 {
480 public:
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.
490 class CRYPTOPP_DLL BitBucket : public Bufferless<Sink>
491 {
492 public:
493 std::string AlgorithmName() const {return "BitBucket";}
494 void IsolatedInitialize(const NameValuePairs &params)
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
500 NAMESPACE_END
501
502 #if CRYPTOPP_MSC_VERSION
503 # pragma warning(pop)
504 #endif
505
506 #endif
AlgorithmImpl
Base class information.
Definition: simple.h:40
AlgorithmImpl::StaticAlgorithmName
static std::string StaticAlgorithmName()
The algorithm name.
Definition: simple.h:46
AlgorithmImpl::AlgorithmName
std::string AlgorithmName() const
The algorithm name.
Definition: simple.h:51
AutoSignaling
Provides auto signaling support.
Definition: simple.h:423
AutoSignaling::GetAutoSignalPropagation
int GetAutoSignalPropagation() const
Retrieve automatic signal propagation value.
Definition: simple.h:439
AutoSignaling::AutoSignaling
AutoSignaling(int propagation=-1)
Construct an AutoSignaling.
Definition: simple.h:427
AutoSignaling::SetAutoSignalPropagation
void SetAutoSignalPropagation(int propagation)
Set propagation of automatically generated and transferred signals.
Definition: simple.h:433
BitBucket
Acts as an input discarding Filter or Sink.
Definition: simple.h:491
BitBucket::Put2
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: simple.h:496
BitBucket::IsolatedInitialize
void IsolatedInitialize(const NameValuePairs &params)
Initialize or reinitialize this object, without signal propagation.
Definition: simple.h:494
BitBucket::AlgorithmName
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: simple.h:493
BufferedTransformation
Interface for buffered transformations.
Definition: cryptlib.h:1657
BufferedTransformation::ChannelFlush
virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output on a channel.
Bufferless
Base class for bufferless filters.
Definition: simple.h:120
Bufferless::IsolatedFlush
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
Definition: simple.h:126
CannotFlush
Flush(true) was called but it can't completely flush its buffers.
Definition: cryptlib.h:248
Clonable
Interface for cloning objects.
Definition: cryptlib.h:590
ClonableImpl
Base class for identifying algorithm.
Definition: simple.h:26
ClonableImpl::Clone
Clonable * Clone() const
Create a copy of this object.
Definition: simple.h:31
CustomFlushPropagation
Interface for custom flush signals propagation.
Definition: simple.h:262
CustomFlushPropagation::Flush
virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)=0
Flush buffered input and/or output, with signal propagation.
CustomSignalPropagation
Interface for custom flush signals.
Definition: simple.h:294
CustomSignalPropagation::Initialize
virtual void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1)=0
Initialize or reinitialize this object, with signal propagation.
InputRejecting
Base class for input rejecting filters.
Definition: simple.h:195
InputRejecting::ChannelMessageSeriesEnd
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
InputRejecting::ChannelPut2
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
InputRejecting::IsolatedMessageSeriesEnd
bool IsolatedMessageSeriesEnd(bool blocking)
Marks the end of a series of messages, without signal propagation.
Definition: simple.h:229
InputRejecting::Put2
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input a byte array for processing.
Definition: simple.h:211
InputRejecting::IsolatedFlush
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
Definition: simple.h:222
InvalidArgument
An invalid argument was detected.
Definition: cryptlib.h:208
InvalidBlockSize
Exception thrown when an invalid block size is encountered.
Definition: simple.h:76
InvalidBlockSize::InvalidBlockSize
InvalidBlockSize(const std::string &algorithm, size_t length)
Construct an InvalidBlockSize.
Definition: simple.h:81
InvalidDerivedKeyLength
Exception thrown when an invalid derived key length is encountered.
Definition: simple.h:86
InvalidDerivedKeyLength::InvalidDerivedKeyLength
InvalidDerivedKeyLength(const std::string &algorithm, size_t length)
Construct an InvalidDerivedKeyLength.
Definition: simple.h:91
InvalidKeyLength
Exception thrown when an invalid key length is encountered.
Definition: simple.h:56
InvalidKeyLength::InvalidKeyLength
InvalidKeyLength(const std::string &algorithm, size_t length)
Construct an InvalidKeyLength.
Definition: simple.h:61
InvalidPersonalizationLength
Exception thrown when an invalid personalization string length is encountered.
Definition: simple.h:96
InvalidPersonalizationLength::InvalidPersonalizationLength
InvalidPersonalizationLength(const std::string &algorithm, size_t length)
Construct an InvalidPersonalizationLength.
Definition: simple.h:101
InvalidRounds
Exception thrown when an invalid number of rounds is encountered.
Definition: simple.h:66
InvalidRounds::InvalidRounds
InvalidRounds(const std::string &algorithm, unsigned int rounds)
Construct an InvalidRounds.
Definition: simple.h:71
InvalidSaltLength
Exception thrown when an invalid salt length is encountered.
Definition: simple.h:106
InvalidSaltLength::InvalidSaltLength
InvalidSaltLength(const std::string &algorithm, size_t length)
Construct an InvalidSaltLength.
Definition: simple.h:111
Multichannel
Multiple channels support for custom signal processing.
Definition: simple.h:316
Multichannel::ChannelFlush
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.
Multichannel::MessageSeriesEnd
bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
Definition: simple.h:329
Multichannel::ChannelPutModifiable2
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
Multichannel::Put2
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: simple.h:351
Multichannel::ChannelPut2
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.
Multichannel::Flush
bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: simple.h:318
Multichannel::ChannelPutModifiable
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
Multichannel::PutModifiable2
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
Multichannel::CreatePutSpace
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: simple.h:341
Multichannel::ChannelCreatePutSpace
byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
Definition: simple.h:378
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:327
NotImplemented
A method was called which was not implemented.
Definition: cryptlib.h:238
Sink
Implementation of BufferedTransformation's attachment interface.
Definition: simple.h:479
Sink::TransferTo2
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
Sink::CopyRangeTo2
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
Store
Acts as a Source for pre-existing, static data.
Definition: simple.h:448
Store::IsolatedInitialize
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: simple.h:453
Store::GetNextMessage
bool GetNextMessage()
Start retrieving the next message.
Store::Store
Store()
Construct a Store.
Definition: simple.h:451
Store::NumberOfMessages
unsigned int NumberOfMessages() const
Provides the number of meesages processed by this object.
Definition: simple.h:459
Unflushable
Base class for unflushable filters.
Definition: simple.h:134
Unflushable::IsolatedFlush
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
Definition: simple.h:162
Unflushable::ChannelFlush
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
Unflushable::Flush
bool Flush(bool completeFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: simple.h:155
config.h
Library configuration file.
CRYPTOPP_API
#define CRYPTOPP_API
Win32 calling convention.
Definition: config_dll.h:119
LWORD_MAX
const lword LWORD_MAX
Large word type max value.
Definition: config_int.h:174
lword
word64 lword
Large word type.
Definition: config_int.h:168
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
DEFAULT_CHANNEL
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Definition: cryptlib.h:516
g_nullNameValuePairs
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
Definition: cryptlib.h:534
misc.h
Utility functions for the Crypto++ library.
IntToString
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition: misc.h:929
CryptoPP
Crypto++ library namespace.
InputRejecting::InputRejected
Definition: simple.h:198
CRYPTOPP_ASSERT
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition: trap.h:68