1#ifndef CRYPTOPP_ZLIB_H
2#define CRYPTOPP_ZLIB_H
3
4#include "adler32.h"
5#include "zdeflate.h"
6#include "zinflate.h"
7
8NAMESPACE_BEGIN(CryptoPP)
9
10/// ZLIB Compressor (RFC 1950)
11class ZlibCompressor : public Deflator
12{
13public:
14	ZlibCompressor(BufferedTransformation *attachment=NULL, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true)
15		: Deflator(attachment, deflateLevel, log2WindowSize, detectUncompressible) {}
16	ZlibCompressor(const NameValuePairs &parameters, BufferedTransformation *attachment=NULL)
17		: Deflator(parameters, attachment) {}
18
19	unsigned int GetCompressionLevel() const;
20
21protected:
22	void WritePrestreamHeader();
23	void ProcessUncompressedData(const byte *string, size_t length);
24	void WritePoststreamTail();
25
26	Adler32 m_adler32;
27};
28
29/// ZLIB Decompressor (RFC 1950)
30class ZlibDecompressor : public Inflator
31{
32public:
33	typedef Inflator::Err Err;
34	class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: header decoding error") {}};
35	class Adler32Err : public Err {public: Adler32Err() : Err(DATA_INTEGRITY_CHECK_FAILED, "ZlibDecompressor: ADLER32 check error") {}};
36	class UnsupportedAlgorithm : public Err {public: UnsupportedAlgorithm() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: unsupported algorithm") {}};
37	class UnsupportedPresetDictionary : public Err {public: UnsupportedPresetDictionary() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: unsupported preset dictionary") {}};
38
39	/*! \param repeat decompress multiple compressed streams in series
40		\param autoSignalPropagation 0 to turn off MessageEnd signal
41	*/
42	ZlibDecompressor(BufferedTransformation *attachment = NULL, bool repeat = false, int autoSignalPropagation = -1);
43	unsigned int GetLog2WindowSize() const {return m_log2WindowSize;}
44
45private:
46	unsigned int MaxPrestreamHeaderSize() const {return 2;}
47	void ProcessPrestreamHeader();
48	void ProcessDecompressedData(const byte *string, size_t length);
49	unsigned int MaxPoststreamTailSize() const {return 4;}
50	void ProcessPoststreamTail();
51
52	unsigned int m_log2WindowSize;
53	Adler32 m_adler32;
54};
55
56NAMESPACE_END
57
58#endif
59