Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

# basecode.h

    00001 #ifndef CRYPTOPP_BASECODE_H
    00002 #define CRYPTOPP_BASECODE_H
    00003
    00004 #include "filters.h"
    00005 #include "algparam.h"
    00006 #include "argnames.h"
    00007
    00008 NAMESPACE_BEGIN(CryptoPP)
    00009
    00010 //! base n encoder, where n is a power of 2
    00011 class CRYPTOPP_DLL BaseN_Encoder : public Unflushable<Filter>
    00012 {
    00013 public:
    00014         BaseN_Encoder(BufferedTransformation *attachment=NULL)
    00015                 {Detach(attachment);}
    00016
    00017         BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULL, int padding=-1)
    00018         {
    00019                 Detach(attachment);
    00020                 IsolatedInitialize(MakeParameters(Name::EncodingLookupArray(), alphabet)
    00021                         (Name::Log2Base(), log2base)
    00022                         (Name::Pad(), padding != -1)
    00023                         (Name::PaddingByte(), byte(padding)));
    00024         }
    00025
    00026         void IsolatedInitialize(const NameValuePairs &parameters);
    00027         unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking);
    00028
    00029 private:
    00030         const byte *m_alphabet;
    00031         int m_padding, m_bitsPerChar, m_outputBlockSize;
    00032         int m_bytePos, m_bitPos;
    00033         SecByteBlock m_outBuf;
    00034 };
    00035
    00036 //! base n decoder, where n is a power of 2
    00037 class CRYPTOPP_DLL BaseN_Decoder : public Unflushable<Filter>
    00038 {
    00039 public:
    00040         BaseN_Decoder(BufferedTransformation *attachment=NULL)
    00041                 {Detach(attachment);}
    00042
    00043         BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULL)
    00044         {
    00045                 Detach(attachment);
    00046                 IsolatedInitialize(MakeParameters(Name::DecodingLookupArray(), lookup)(Name::Log2Base(), log2base));
    00047         }
    00048
    00049         void IsolatedInitialize(const NameValuePairs &parameters);
    00050         unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking);
    00051
    00052         static void InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive);
    00053
    00054 private:
    00055         const int *m_lookup;
    00056         int m_padding, m_bitsPerChar, m_outputBlockSize;
    00057         int m_bytePos, m_bitPos;
    00058         SecByteBlock m_outBuf;
    00059 };
    00060
    00061 //! filter that breaks input stream into groups of fixed size
    00062 class CRYPTOPP_DLL Grouper : public Bufferless<Filter>
    00063 {
    00064 public:
    00065         Grouper(BufferedTransformation *attachment=NULL)
    00066                 {Detach(attachment);}
    00067
    00068         Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULL)
    00069         {
    00070                 Detach(attachment);
    00071                 IsolatedInitialize(MakeParameters(Name::GroupSize(), groupSize)
    00072                         (Name::Separator(), ConstByteArrayParameter(separator))
    00073                         (Name::Terminator(), ConstByteArrayParameter(terminator)));
    00074         }
    00075
    00076         void IsolatedInitialize(const NameValuePairs &parameters);
    00077         unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking);
    00078
    00079 private:
    00080         SecByteBlock m_separator, m_terminator;
    00081         unsigned int m_groupSize, m_counter;
    00082 };
    00083
    00084 NAMESPACE_END
    00085
    00086 #endif