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