1#ifndef CRYPTOPP_GZIP_H 2#define CRYPTOPP_GZIP_H 3 4#include "zdeflate.h" 5#include "zinflate.h" 6#include "crc.h" 7 8NAMESPACE_BEGIN(CryptoPP) 9 10/// GZIP Compression (RFC 1952) 11class Gzip : public Deflator 12{ 13public: 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) {} 16 Gzip(const NameValuePairs ¶meters, BufferedTransformation *attachment=NULL) 17 : Deflator(parameters, attachment) {} 18 19protected: 20 enum {MAGIC1=0x1f, MAGIC2=0x8b, // flags for the header 21 DEFLATED=8, FAST=4, SLOW=2}; 22 23 void WritePrestreamHeader(); 24 void ProcessUncompressedData(const byte *string, size_t length); 25 void WritePoststreamTail(); 26 27 word32 m_totalLen; 28 CRC32 m_crc; 29}; 30 31/// GZIP Decompression (RFC 1952) 32class Gunzip : public Inflator 33{ 34public: 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 46protected: 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(); 55 void ProcessDecompressedData(const byte *string, size_t length); 56 unsigned int MaxPoststreamTailSize() const {return 8;} 57 void ProcessPoststreamTail(); 58 59 word32 m_length; 60 CRC32 m_crc; 61}; 62 63NAMESPACE_END 64 65#endif 66