File indexing completed on 2025-01-18 09:54:54
0001
0002
0003
0004
0005
0006 #ifndef CRYPTOPP_BASECODE_H
0007 #define CRYPTOPP_BASECODE_H
0008
0009 #include "cryptlib.h"
0010 #include "filters.h"
0011 #include "algparam.h"
0012 #include "argnames.h"
0013
0014 NAMESPACE_BEGIN(CryptoPP)
0015
0016
0017 class CRYPTOPP_DLL BaseN_Encoder : public Unflushable<Filter>
0018 {
0019 public:
0020
0021
0022 BaseN_Encoder(BufferedTransformation *attachment=NULLPTR)
0023 : m_alphabet(NULLPTR), m_padding(0), m_bitsPerChar(0)
0024 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
0025 {Detach(attachment);}
0026
0027
0028
0029
0030
0031
0032
0033
0034 BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULLPTR, int padding=-1)
0035 : m_alphabet(NULLPTR), m_padding(0), m_bitsPerChar(0)
0036 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
0037 {
0038 Detach(attachment);
0039 BaseN_Encoder::IsolatedInitialize(
0040 MakeParameters
0041 (Name::EncodingLookupArray(), alphabet)
0042 (Name::Log2Base(), log2base)
0043 (Name::Pad(), padding != -1)
0044 (Name::PaddingByte(), byte(padding)));
0045 }
0046
0047 void IsolatedInitialize(const NameValuePairs ¶meters);
0048 size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
0049
0050 private:
0051 const byte *m_alphabet;
0052 int m_padding, m_bitsPerChar, m_outputBlockSize;
0053 int m_bytePos, m_bitPos;
0054 SecByteBlock m_outBuf;
0055 };
0056
0057
0058 class CRYPTOPP_DLL BaseN_Decoder : public Unflushable<Filter>
0059 {
0060 public:
0061
0062
0063
0064
0065 BaseN_Decoder(BufferedTransformation *attachment=NULLPTR)
0066 : m_lookup(NULLPTR), m_bitsPerChar(0)
0067 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
0068 {Detach(attachment);}
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULLPTR)
0079 : m_lookup(NULLPTR), m_bitsPerChar(0)
0080 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
0081 {
0082 Detach(attachment);
0083 BaseN_Decoder::IsolatedInitialize(
0084 MakeParameters
0085 (Name::DecodingLookupArray(), lookup)
0086 (Name::Log2Base(), log2base));
0087 }
0088
0089 void IsolatedInitialize(const NameValuePairs ¶meters);
0090 size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 static void CRYPTOPP_API InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive);
0103
0104 private:
0105 const int *m_lookup;
0106 int m_bitsPerChar, m_outputBlockSize;
0107 int m_bytePos, m_bitPos;
0108 SecByteBlock m_outBuf;
0109 };
0110
0111
0112 class CRYPTOPP_DLL Grouper : public Bufferless<Filter>
0113 {
0114 public:
0115
0116
0117 Grouper(BufferedTransformation *attachment=NULLPTR)
0118 : m_groupSize(0), m_counter(0) {Detach(attachment);}
0119
0120
0121
0122
0123
0124
0125 Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULLPTR)
0126 : m_groupSize(0), m_counter(0)
0127 {
0128 Detach(attachment);
0129 Grouper::IsolatedInitialize(
0130 MakeParameters
0131 (Name::GroupSize(), groupSize)
0132 (Name::Separator(), ConstByteArrayParameter(separator))
0133 (Name::Terminator(), ConstByteArrayParameter(terminator)));
0134 }
0135
0136 void IsolatedInitialize(const NameValuePairs ¶meters);
0137 size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
0138
0139 private:
0140 SecByteBlock m_separator, m_terminator;
0141 size_t m_groupSize, m_counter;
0142 };
0143
0144 NAMESPACE_END
0145
0146 #endif