Fabcoin Core  0.16.2
P2P Digital Currency
simple.h
Go to the documentation of this file.
1 // simple.h - written and placed in the public domain by Wei Dai
2 
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 
20 
21 template <class DERIVED, class BASE>
26 class CRYPTOPP_NO_VTABLE ClonableImpl : public BASE
27 {
28 public:
29  Clonable * Clone() const {return new DERIVED(*static_cast<const DERIVED *>(this));}
30 };
31 
37 template <class BASE, class ALGORITHM_INFO=BASE>
38 class CRYPTOPP_NO_VTABLE AlgorithmImpl : public BASE
39 {
40 public:
41  static std::string CRYPTOPP_API StaticAlgorithmName() {return ALGORITHM_INFO::StaticAlgorithmName();}
42  std::string AlgorithmName() const {return ALGORITHM_INFO::StaticAlgorithmName();}
43 };
44 
48 {
49 public:
50  explicit InvalidKeyLength(const std::string &algorithm, size_t length) : InvalidArgument(algorithm + ": " + IntToString(length) + " is not a valid key length") {}
51 };
52 
56 {
57 public:
58  explicit InvalidRounds(const std::string &algorithm, unsigned int rounds) : InvalidArgument(algorithm + ": " + IntToString(rounds) + " is not a valid number of rounds") {}
59 };
60 
64 {
65 public:
66  explicit InvalidPersonalizationLength(const std::string &algorithm, size_t length) : InvalidArgument(algorithm + ": " + IntToString(length) + " is not a valid salt length") {}
67 };
68 
72 {
73 public:
74  explicit InvalidSaltLength(const std::string &algorithm, size_t length) : InvalidArgument(algorithm + ": " + IntToString(length) + " is not a valid salt length") {}
75 };
76 
77 // *****************************
78 
82 template <class T>
84 {
85 public:
86  bool IsolatedFlush(bool hardFlush, bool blocking)
87  {CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); return false;}
88 };
89 
93 template <class T>
95 {
96 public:
97  bool Flush(bool completeFlush, int propagation=-1, bool blocking=true)
98  {return ChannelFlush(DEFAULT_CHANNEL, completeFlush, propagation, blocking);}
99  bool IsolatedFlush(bool hardFlush, bool blocking)
100  {CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); CRYPTOPP_ASSERT(false); return false;}
101  bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
102  {
103  if (hardFlush && !InputBufferIsEmpty())
104  throw CannotFlush("Unflushable<T>: this object has buffered input that cannot be flushed");
105  else
106  {
107  BufferedTransformation *attached = this->AttachedTransformation();
108  return attached && propagation ? attached->ChannelFlush(channel, hardFlush, propagation-1, blocking) : false;
109  }
110  }
111 
112 protected:
113  virtual bool InputBufferIsEmpty() const {return false;}
114 };
115 
120 template <class T>
122 {
123 public:
125  {InputRejected() : NotImplemented("BufferedTransformation: this object doesn't allow input") {}};
126 
128 
129 
138  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
139  {CRYPTOPP_UNUSED(inString); CRYPTOPP_UNUSED(length); CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking); throw InputRejected();}
141 
143 
144  bool IsolatedFlush(bool hardFlush, bool blocking)
145  {CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); return false;}
146  bool IsolatedMessageSeriesEnd(bool blocking)
147  {CRYPTOPP_UNUSED(blocking); throw InputRejected();}
148  size_t ChannelPut2(const std::string &channel, const byte *inString, size_t length, int messageEnd, bool blocking)
149  {CRYPTOPP_UNUSED(channel); CRYPTOPP_UNUSED(inString); CRYPTOPP_UNUSED(length); CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking); throw InputRejected();}
150  bool ChannelMessageSeriesEnd(const std::string& channel, int messageEnd, bool blocking)
151  {CRYPTOPP_UNUSED(channel); CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking); throw InputRejected();}
153 };
154 
158 template <class T>
160 {
161 public:
163 
164 
179  virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true) =0;
180 
182 
183 private:
184  bool IsolatedFlush(bool hardFlush, bool blocking)
185  {CRYPTOPP_UNUSED(hardFlush); CRYPTOPP_UNUSED(blocking); CRYPTOPP_ASSERT(false); return false;}
186 };
187 
191 template <class T>
193 {
194 public:
203  virtual void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1) =0;
204 
205 private:
207  {CRYPTOPP_UNUSED(parameters); CRYPTOPP_ASSERT(false);}
208 };
209 
214 template <class T>
216 {
217 public:
218  bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
219  {return this->ChannelFlush(DEFAULT_CHANNEL, hardFlush, propagation, blocking);}
220 
229  bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
230  {return this->ChannelMessageSeriesEnd(DEFAULT_CHANNEL, propagation, blocking);}
231 
242  {return this->ChannelCreatePutSpace(DEFAULT_CHANNEL, size);}
243 
250  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
251  {return this->ChannelPut2(DEFAULT_CHANNEL, inString, length, messageEnd, blocking);}
252 
259  size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking)
260  {return this->ChannelPutModifiable2(DEFAULT_CHANNEL, inString, length, messageEnd, blocking);}
261 
262 // void ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1)
263 // {PropagateMessageSeriesEnd(propagation, channel);}
264  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
265  {CRYPTOPP_UNUSED(channel); size = 0; return NULL;}
266  bool ChannelPutModifiable(const std::string &channel, byte *inString, size_t length)
267  {this->ChannelPut(channel, inString, length); return false;}
268 
269  virtual size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking) =0;
270  size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
271  {return ChannelPut2(channel, begin, length, messageEnd, blocking);}
272 
273  virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true) =0;
274 };
275 
279 template <class T>
281 {
282 public:
285  AutoSignaling(int propagation=-1) : m_autoSignalPropagation(propagation) {}
286 
287  void SetAutoSignalPropagation(int propagation)
288  {m_autoSignalPropagation = propagation;}
290  {return m_autoSignalPropagation;}
291 
292 private:
294 };
295 
299 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Store : public AutoSignaling<InputRejecting<BufferedTransformation> >
300 {
301 public:
303  Store() : m_messageEnd(false) {}
304 
306  {
307  m_messageEnd = false;
308  StoreInitialize(parameters);
309  }
310 
311  unsigned int NumberOfMessages() const {return m_messageEnd ? 0 : 1;}
312  bool GetNextMessage();
313  unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const;
314 
315 protected:
316  virtual void StoreInitialize(const NameValuePairs &parameters) =0;
317 
319 };
320 
332 {
333 public:
334  size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
335  {CRYPTOPP_UNUSED(target); CRYPTOPP_UNUSED(transferBytes); CRYPTOPP_UNUSED(channel); CRYPTOPP_UNUSED(blocking); transferBytes = 0; return 0;}
336  size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
337  {CRYPTOPP_UNUSED(target); CRYPTOPP_UNUSED(begin); CRYPTOPP_UNUSED(end); CRYPTOPP_UNUSED(channel); CRYPTOPP_UNUSED(blocking); return 0;}
338 };
339 
345 class CRYPTOPP_DLL BitBucket : public Bufferless<Sink>
346 {
347 public:
348  std::string AlgorithmName() const {return "BitBucket";}
349  void IsolatedInitialize(const NameValuePairs &params)
350  {CRYPTOPP_UNUSED(params);}
351  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
352  {CRYPTOPP_UNUSED(inString); CRYPTOPP_UNUSED(length); CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking); return 0;}
353 };
354 
356 
357 #if CRYPTOPP_MSC_VERSION
358 # pragma warning(pop)
359 #endif
360 
361 #endif
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: simple.h:250
An invalid argument was detected.
Definition: cryptlib.h:184
bool Flush(bool completeFlush, int propagation=-1, bool blocking=true)
Definition: simple.h:97
std::string AlgorithmName() const
Definition: simple.h:42
size_t ChannelPut2(const std::string &channel, const byte *inString, size_t length, int messageEnd, bool blocking)
Definition: simple.h:148
uint8_t byte
Definition: Common.h:57
bool IsolatedFlush(bool hardFlush, bool blocking)
Definition: simple.h:86
const lword LWORD_MAX
Definition: config.h:246
Utility functions for the Crypto++ library.
Store()
Construct a Store.
Definition: simple.h:303
bool IsolatedFlush(bool hardFlush, bool blocking)
Definition: simple.h:99
InvalidPersonalizationLength(const std::string &algorithm, size_t length)
Definition: simple.h:66
virtual bool InputBufferIsEmpty() const
Definition: simple.h:113
Base class for identifying alogorithm.
Definition: simple.h:26
Exception thrown when an invalid key length is encountered.
Definition: simple.h:47
bool ChannelPutModifiable(const std::string &channel, byte *inString, size_t length)
Definition: simple.h:266
#define T(i, x)
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
size_t count
Definition: ExecStats.cpp:37
Flush(true) was called but it can&#39;t completely flush its buffers.
Definition: cryptlib.h:212
Abstract base classes that provide a uniform interface to this library.
bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: simple.h:218
void IsolatedInitialize(const NameValuePairs &params)
Initialize or reinitialize this object, without signal propagation.
Definition: simple.h:349
void IsolatedInitialize(const NameValuePairs &parameters)
Definition: simple.h:206
Library configuration file.
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: simple.h:348
Acts as a Source for pre-existing, static data.
Definition: simple.h:299
Base class for input rejecting filters.
Definition: simple.h:121
byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Definition: simple.h:264
bool IsolatedFlush(bool hardFlush, bool blocking)
Definition: simple.h:144
virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output on a channel.
Definition: cryptlib.cpp:480
Interface for buffered transformations.
Definition: cryptlib.h:1352
Interface for cloning objects.
Definition: cryptlib.h:482
Interface for custom flush signals propagation.
Definition: simple.h:159
Exception thrown when an invalid salt length is encountered.
Definition: simple.h:71
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Definition: cryptlib.cpp:59
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: simple.h:305
InvalidSaltLength(const std::string &algorithm, size_t length)
Definition: simple.h:74
Exception thrown when an invalid personalization string length is encountered.
Definition: simple.h:63
static std::string CRYPTOPP_API StaticAlgorithmName()
Definition: simple.h:41
void SetAutoSignalPropagation(int propagation)
Definition: simple.h:287
A method was called which was not implemented.
Definition: cryptlib.h:205
Exception thrown when an invalid number of rounds is encountered.
Definition: simple.h:55
bool m_messageEnd
Definition: simple.h:318
int m_autoSignalPropagation
Definition: simple.h:293
#define CRYPTOPP_API
Definition: config.h:705
InvalidKeyLength(const std::string &algorithm, size_t length)
Definition: simple.h:50
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:334
bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
Definition: simple.h:101
#define CRYPTOPP_ASSERT(exp)
Definition: trap.h:92
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input a byte array for processing.
Definition: simple.h:138
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
Definition: cryptlib.cpp:76
#define CRYPTOPP_NO_VTABLE
Definition: config.h:369
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:336
size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee.
Definition: simple.h:259
Base class for unflushable filters.
Definition: simple.h:94
uint8_t const size_t const size
Definition: sha3.h:20
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: simple.h:351
#define CRYPTOPP_UNUSED(x)
Definition: config.h:741
Implementation of BufferedTransformation&#39;s attachment interface.
Definition: simple.h:331
Provides auto signaling support.
Definition: simple.h:280
int GetAutoSignalPropagation() const
Definition: simple.h:289
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition: misc.h:539
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: simple.h:241
bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
Definition: simple.h:229
#define NAMESPACE_END
Definition: config.h:201
std::vector< char * > parameters
Definition: boostTest.cpp:46
Acts as an input discarding Filter or Sink.
Definition: simple.h:345
bool IsolatedFlush(bool hardFlush, bool blocking)
Definition: simple.h:184
word64 lword
Definition: config.h:245
size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
Definition: simple.h:270
#define CRYPTOPP_DLL
Definition: config.h:704
unsigned int NumberOfMessages() const
Provides the number of meesages processed by this object.
Definition: simple.h:311
Multiple channels support for custom signal processing.
Definition: simple.h:215
Interface for custom flush signals.
Definition: simple.h:192
bool IsolatedMessageSeriesEnd(bool blocking)
Definition: simple.h:146
bool ChannelMessageSeriesEnd(const std::string &channel, int messageEnd, bool blocking)
Definition: simple.h:150
InvalidRounds(const std::string &algorithm, unsigned int rounds)
Definition: simple.h:58
AutoSignaling(int propagation=-1)
Construct an AutoSignaling.
Definition: simple.h:285
Base class for bufferless filters.
Definition: simple.h:83
Clonable * Clone() const
Definition: simple.h:29
Interface for retrieving values given their names.
Definition: cryptlib.h:279
Base class for identifying alogorithm.
Definition: simple.h:38