00001
00002
00003
00004
00005
00006 #ifndef CRYPTOPP_BASECODE_H
00007 #define CRYPTOPP_BASECODE_H
00008
00009 #include "cryptlib.h"
00010 #include "filters.h"
00011 #include "algparam.h"
00012 #include "argnames.h"
00013
00014 NAMESPACE_BEGIN(CryptoPP)
00015
00016
00017
00018 class CRYPTOPP_DLL BaseN_Encoder : public Unflushable<Filter>
00019 {
00020 public:
00021
00022
00023 BaseN_Encoder(BufferedTransformation *attachment=NULL)
00024 : m_alphabet(NULL), m_padding(0), m_bitsPerChar(0)
00025 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
00026 {Detach(attachment);}
00027
00028
00029
00030
00031
00032
00033
00034
00035 BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULL, int padding=-1)
00036 : m_alphabet(NULL), m_padding(0), m_bitsPerChar(0)
00037 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
00038 {
00039 Detach(attachment);
00040 IsolatedInitialize(MakeParameters(Name::EncodingLookupArray(), alphabet)
00041 (Name::Log2Base(), log2base)
00042 (Name::Pad(), padding != -1)
00043 (Name::PaddingByte(), byte(padding)));
00044 }
00045
00046 void IsolatedInitialize(const NameValuePairs ¶meters);
00047 size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
00048
00049 private:
00050 const byte *m_alphabet;
00051 int m_padding, m_bitsPerChar, m_outputBlockSize;
00052 int m_bytePos, m_bitPos;
00053 SecByteBlock m_outBuf;
00054 };
00055
00056
00057
00058 class CRYPTOPP_DLL BaseN_Decoder : public Unflushable<Filter>
00059 {
00060 public:
00061
00062
00063
00064
00065 BaseN_Decoder(BufferedTransformation *attachment=NULL)
00066 : m_lookup(0), m_padding(0), m_bitsPerChar(0)
00067 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
00068 {Detach(attachment);}
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULL)
00079 : m_lookup(0), m_padding(0), m_bitsPerChar(0)
00080 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
00081 {
00082 Detach(attachment);
00083 IsolatedInitialize(MakeParameters(Name::DecodingLookupArray(), lookup)(Name::Log2Base(), log2base));
00084 }
00085
00086 void IsolatedInitialize(const NameValuePairs ¶meters);
00087 size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 static void CRYPTOPP_API InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive);
00100
00101 private:
00102 const int *m_lookup;
00103 int m_padding, m_bitsPerChar, m_outputBlockSize;
00104 int m_bytePos, m_bitPos;
00105 SecByteBlock m_outBuf;
00106 };
00107
00108
00109
00110 class CRYPTOPP_DLL Grouper : public Bufferless<Filter>
00111 {
00112 public:
00113
00114
00115 Grouper(BufferedTransformation *attachment=NULL)
00116 : m_groupSize(0), m_counter(0) {Detach(attachment);}
00117
00118
00119
00120
00121
00122
00123 Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULL)
00124 : m_groupSize(0), m_counter(0)
00125 {
00126 Detach(attachment);
00127 IsolatedInitialize(MakeParameters(Name::GroupSize(), groupSize)
00128 (Name::Separator(), ConstByteArrayParameter(separator))
00129 (Name::Terminator(), ConstByteArrayParameter(terminator)));
00130 }
00131
00132 void IsolatedInitialize(const NameValuePairs ¶meters);
00133 size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
00134
00135 private:
00136 SecByteBlock m_separator, m_terminator;
00137 size_t m_groupSize, m_counter;
00138 };
00139
00140 NAMESPACE_END
00141
00142 #endif