00001 #ifndef CRYPTOPP_ZLIB_H
00002 #define CRYPTOPP_ZLIB_H
00003
00004 #include "adler32.h"
00005 #include "zdeflate.h"
00006 #include "zinflate.h"
00007
00008 NAMESPACE_BEGIN(CryptoPP)
00009
00011 class ZlibCompressor : public Deflator
00012 {
00013 public:
00014 ZlibCompressor(BufferedTransformation *outQ=NULL, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE);
00015
00016 unsigned int GetCompressionLevel() const;
00017
00018 private:
00019 void WritePrestreamHeader();
00020 void ProcessUncompressedData(const byte *string, unsigned int length);
00021 void WritePoststreamTail();
00022
00023 Adler32 m_adler32;
00024 };
00025
00027 class ZlibDecompressor : public Inflator
00028 {
00029 public:
00030 typedef Inflator::Err Err;
00031 class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: header decoding error") {}};
00032 class Adler32Err : public Err {public: Adler32Err() : Err(DATA_INTEGRITY_CHECK_FAILED, "ZlibDecompressor: ADLER32 check error") {}};
00033 class UnsupportedAlgorithm : public Err {public: UnsupportedAlgorithm() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: unsupported algorithm") {}};
00034 class UnsupportedPresetDictionary : public Err {public: UnsupportedPresetDictionary() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: unsupported preset dictionary") {}};
00035
00036 ZlibDecompressor(BufferedTransformation *outQueue = NULL, bool repeat = false);
00037 unsigned int GetLog2WindowSize() const {return m_log2WindowSize;}
00038
00039 private:
00040 unsigned int MaxPrestreamHeaderSize() const {return 2;}
00041 void ProcessPrestreamHeader();
00042 void ProcessDecompressedData(const byte *string, unsigned int length);
00043 unsigned int MaxPoststreamTailSize() const {return 4;}
00044 void ProcessPoststreamTail();
00045
00046 unsigned int m_log2WindowSize;
00047 Adler32 m_adler32;
00048 };
00049
00050 NAMESPACE_END
00051
00052 #endif