ext-cryptopp/basecode.h

87 lines
2.5 KiB
C
Raw Normal View History

2002-10-04 17:31:41 +00:00
#ifndef CRYPTOPP_BASECODE_H
#define CRYPTOPP_BASECODE_H
#include "filters.h"
#include "algparam.h"
2003-07-18 04:35:30 +00:00
#include "argnames.h"
2002-10-04 17:31:41 +00:00
NAMESPACE_BEGIN(CryptoPP)
//! base n encoder, where n is a power of 2
class CRYPTOPP_DLL BaseN_Encoder : public Unflushable<Filter>
2002-10-04 17:31:41 +00:00
{
public:
BaseN_Encoder(BufferedTransformation *attachment=NULL)
2003-07-18 21:33:18 +00:00
{Detach(attachment);}
2002-10-04 17:31:41 +00:00
BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULL, int padding=-1)
{
2003-07-18 21:33:18 +00:00
Detach(attachment);
2003-07-18 04:35:30 +00:00
IsolatedInitialize(MakeParameters(Name::EncodingLookupArray(), alphabet)
(Name::Log2Base(), log2base)
(Name::Pad(), padding != -1)
(Name::PaddingByte(), byte(padding)));
2002-10-04 17:31:41 +00:00
}
void IsolatedInitialize(const NameValuePairs &parameters);
2005-07-12 04:23:32 +00:00
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
2002-10-04 17:31:41 +00:00
private:
const byte *m_alphabet;
int m_padding, m_bitsPerChar, m_outputBlockSize;
int m_bytePos, m_bitPos;
SecByteBlock m_outBuf;
};
//! base n decoder, where n is a power of 2
class CRYPTOPP_DLL BaseN_Decoder : public Unflushable<Filter>
2002-10-04 17:31:41 +00:00
{
public:
BaseN_Decoder(BufferedTransformation *attachment=NULL)
2003-07-18 21:33:18 +00:00
{Detach(attachment);}
2002-10-04 17:31:41 +00:00
BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULL)
{
2003-07-18 21:33:18 +00:00
Detach(attachment);
2003-07-18 04:35:30 +00:00
IsolatedInitialize(MakeParameters(Name::DecodingLookupArray(), lookup)(Name::Log2Base(), log2base));
2002-10-04 17:31:41 +00:00
}
void IsolatedInitialize(const NameValuePairs &parameters);
2005-07-12 04:23:32 +00:00
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
2002-10-04 17:31:41 +00:00
2005-09-05 21:43:43 +00:00
static void CRYPTOPP_API InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive);
2002-10-04 17:31:41 +00:00
private:
const int *m_lookup;
int m_padding, m_bitsPerChar, m_outputBlockSize;
int m_bytePos, m_bitPos;
SecByteBlock m_outBuf;
};
//! filter that breaks input stream into groups of fixed size
class CRYPTOPP_DLL Grouper : public Bufferless<Filter>
2002-10-04 17:31:41 +00:00
{
public:
Grouper(BufferedTransformation *attachment=NULL)
2003-07-18 21:33:18 +00:00
{Detach(attachment);}
2002-10-04 17:31:41 +00:00
2003-03-20 01:24:12 +00:00
Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULL)
2002-10-04 17:31:41 +00:00
{
2003-07-18 21:33:18 +00:00
Detach(attachment);
2003-07-18 04:35:30 +00:00
IsolatedInitialize(MakeParameters(Name::GroupSize(), groupSize)
(Name::Separator(), ConstByteArrayParameter(separator))
(Name::Terminator(), ConstByteArrayParameter(terminator)));
2002-10-04 17:31:41 +00:00
}
void IsolatedInitialize(const NameValuePairs &parameters);
2005-07-12 04:23:32 +00:00
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
2002-10-04 17:31:41 +00:00
private:
2003-03-20 01:24:12 +00:00
SecByteBlock m_separator, m_terminator;
2005-07-12 04:23:32 +00:00
size_t m_groupSize, m_counter;
2002-10-04 17:31:41 +00:00
};
NAMESPACE_END
#endif