Fabcoin Core  0.16.2
P2P Digital Currency
basecode.h
Go to the documentation of this file.
1 // basecode.h - written and placed in the public domain by Wei Dai
2 
5 
6 #ifndef CRYPTOPP_BASECODE_H
7 #define CRYPTOPP_BASECODE_H
8 
9 #include "cryptlib.h"
10 #include "filters.h"
11 #include "algparam.h"
12 #include "argnames.h"
13 
15 
19 {
20 public:
24  : m_alphabet(NULL), m_padding(0), m_bitsPerChar(0)
25  , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
26  {Detach(attachment);}
27 
35  BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULL, int padding=-1)
36  : m_alphabet(NULL), m_padding(0), m_bitsPerChar(0)
37  , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
38  {
39  Detach(attachment);
40  IsolatedInitialize(MakeParameters(Name::EncodingLookupArray(), alphabet)
41  (Name::Log2Base(), log2base)
42  (Name::Pad(), padding != -1)
43  (Name::PaddingByte(), byte(padding)));
44  }
45 
46  void IsolatedInitialize(const NameValuePairs &parameters);
47  size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
48 
49 private:
50  const byte *m_alphabet;
51  int m_padding, m_bitsPerChar, m_outputBlockSize;
52  int m_bytePos, m_bitPos;
54 };
55 
58 class CRYPTOPP_DLL BaseN_Decoder : public Unflushable<Filter>
59 {
60 public:
66  : m_lookup(0), m_padding(0), m_bitsPerChar(0)
67  , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
68  {Detach(attachment);}
69 
78  BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULL)
79  : m_lookup(0), m_padding(0), m_bitsPerChar(0)
80  , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
81  {
82  Detach(attachment);
83  IsolatedInitialize(MakeParameters(Name::DecodingLookupArray(), lookup)(Name::Log2Base(), log2base));
84  }
85 
86  void IsolatedInitialize(const NameValuePairs &parameters);
87  size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
88 
99  static void CRYPTOPP_API InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive);
100 
101 private:
102  const int *m_lookup;
103  int m_padding, m_bitsPerChar, m_outputBlockSize;
104  int m_bytePos, m_bitPos;
106 };
107 
110 class CRYPTOPP_DLL Grouper : public Bufferless<Filter>
111 {
112 public:
115  Grouper(BufferedTransformation *attachment=NULL)
116  : m_groupSize(0), m_counter(0) {Detach(attachment);}
117 
123  Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULL)
124  : m_groupSize(0), m_counter(0)
125  {
126  Detach(attachment);
127  IsolatedInitialize(MakeParameters(Name::GroupSize(), groupSize)
128  (Name::Separator(), ConstByteArrayParameter(separator))
129  (Name::Terminator(), ConstByteArrayParameter(terminator)));
130  }
131 
132  void IsolatedInitialize(const NameValuePairs &parameters);
133  size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
134 
135 private:
137  size_t m_groupSize, m_counter;
138 };
139 
141 
142 #endif
Used to pass byte array input as part of a NameValuePairs object.
Definition: algparam.h:29
Standard names for retrieving values by name when working with NameValuePairs.
Classes for working with NameValuePairs.
uint8_t byte
Definition: Common.h:57
int m_padding
Definition: basecode.h:51
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Grouper(BufferedTransformation *attachment=NULL)
Construct a Grouper.
Definition: basecode.h:115
Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULL)
Construct a Grouper.
Definition: basecode.h:123
Abstract base classes that provide a uniform interface to this library.
BaseN_Encoder(BufferedTransformation *attachment=NULL)
Construct a BaseN_Encoder.
Definition: basecode.h:23
SecByteBlock m_outBuf
Definition: basecode.h:105
SecByteBlock m_terminator
Definition: basecode.h:136
Interface for buffered transformations.
Definition: cryptlib.h:1352
SecByteBlock m_outBuf
Definition: basecode.h:53
const int * m_lookup
Definition: basecode.h:102
BaseN_Decoder(BufferedTransformation *attachment=NULL)
Construct a BaseN_Decoder.
Definition: basecode.h:65
int m_bytePos
Definition: basecode.h:52
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:498
BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULL)
Construct a BaseN_Decoder.
Definition: basecode.h:78
#define CRYPTOPP_API
Definition: config.h:705
Implementation of BufferedTransformation&#39;s attachment interface.
BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULL, int padding=-1)
Construct a BaseN_Encoder.
Definition: basecode.h:35
Base class for unflushable filters.
Definition: simple.h:94
const byte * m_alphabet
Definition: basecode.h:50
uint8_t byte
Definition: Common.h:10
Implementation of BufferedTransformation&#39;s attachment interface.
Definition: filters.h:36
Filter that breaks input stream into groups of fixed size.
Definition: basecode.h:110
#define NAMESPACE_END
Definition: config.h:201
std::vector< char * > parameters
Definition: boostTest.cpp:46
Encoder for bases that are a power of 2.
Definition: basecode.h:18
#define CRYPTOPP_DLL
Definition: config.h:704
size_t m_groupSize
Definition: basecode.h:137
Decoder for bases that are a power of 2.
Definition: basecode.h:58
Base class for bufferless filters.
Definition: simple.h:83
Interface for retrieving values given their names.
Definition: cryptlib.h:279