~zooko/cryptopp/trunk

1 by weidai
Initial revision
1
#ifndef CRYPTOPP_GZIP_H
2
#define CRYPTOPP_GZIP_H
3
4
#include "zdeflate.h"
5
#include "zinflate.h"
6
#include "crc.h"
7
8
NAMESPACE_BEGIN(CryptoPP)
9
10
/// GZIP Compression (RFC 1952)
11
class Gzip : public Deflator
12
{
13
public:
144 by weidai
add detection of uncompressibilty
14
	Gzip(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) {}
1 by weidai
Initial revision
16
	Gzip(const NameValuePairs &parameters, BufferedTransformation *attachment=NULL)
17
		: Deflator(parameters, attachment) {}
18
19
protected:
20
	enum {MAGIC1=0x1f, MAGIC2=0x8b,   // flags for the header
21
		  DEFLATED=8, FAST=4, SLOW=2};
22
23
	void WritePrestreamHeader();
184 by weidai
port to MSVC .NET 2005 beta 2
24
	void ProcessUncompressedData(const byte *string, size_t length);
1 by weidai
Initial revision
25
	void WritePoststreamTail();
26
184 by weidai
port to MSVC .NET 2005 beta 2
27
	word32 m_totalLen;
1 by weidai
Initial revision
28
	CRC32 m_crc;
29
};
30
31
/// GZIP Decompression (RFC 1952)
32
class Gunzip : public Inflator
33
{
34
public:
35
	typedef Inflator::Err Err;
36
	class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "Gunzip: header decoding error") {}};
37
	class TailErr : public Err {public: TailErr() : Err(INVALID_DATA_FORMAT, "Gunzip: tail too short") {}};
38
	class CrcErr : public Err {public: CrcErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: CRC check error") {}};
39
	class LengthErr : public Err {public: LengthErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: length check error") {}};
40
41
	/*! \param repeat decompress multiple compressed streams in series
42
		\param autoSignalPropagation 0 to turn off MessageEnd signal
43
	*/
44
	Gunzip(BufferedTransformation *attachment = NULL, bool repeat = false, int autoSignalPropagation = -1);
45
46
protected:
47
	enum {MAGIC1=0x1f, MAGIC2=0x8b,   // flags for the header
48
		DEFLATED=8};
49
50
	enum FLAG_MASKS {
51
		CONTINUED=2, EXTRA_FIELDS=4, FILENAME=8, COMMENTS=16, ENCRYPTED=32};
52
53
	unsigned int MaxPrestreamHeaderSize() const {return 1024;}
54
	void ProcessPrestreamHeader();
184 by weidai
port to MSVC .NET 2005 beta 2
55
	void ProcessDecompressedData(const byte *string, size_t length);
1 by weidai
Initial revision
56
	unsigned int MaxPoststreamTailSize() const {return 8;}
57
	void ProcessPoststreamTail();
58
184 by weidai
port to MSVC .NET 2005 beta 2
59
	word32 m_length;
1 by weidai
Initial revision
60
	CRC32 m_crc;
61
};
62
63
NAMESPACE_END
64
65
#endif