00001 #ifndef CRYPTOPP_GZIP_H
00002 #define CRYPTOPP_GZIP_H
00003
00004 #include "cryptlib.h"
00005 #include "zdeflate.h"
00006 #include "zinflate.h"
00007 #include "crc.h"
00008
00009 NAMESPACE_BEGIN(CryptoPP)
00010
00011
00012 class Gzip : public Deflator
00013 {
00014 public:
00015 Gzip(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), m_totalLen(0) {}
00017 Gzip(const NameValuePairs ¶meters, BufferedTransformation *attachment=NULL)
00018 : Deflator(parameters, attachment), m_totalLen(0) {}
00019
00020 protected:
00021 enum {MAGIC1=0x1f, MAGIC2=0x8b,
00022 DEFLATED=8, FAST=4, SLOW=2};
00023
00024 void WritePrestreamHeader();
00025 void ProcessUncompressedData(const byte *string, size_t length);
00026 void WritePoststreamTail();
00027
00028 word32 m_totalLen;
00029 CRC32 m_crc;
00030 };
00031
00032
00033
00034 class Gunzip : public Inflator
00035 {
00036 public:
00037 typedef Inflator::Err Err;
00038 class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "Gunzip: header decoding error") {}};
00039 class TailErr : public Err {public: TailErr() : Err(INVALID_DATA_FORMAT, "Gunzip: tail too short") {}};
00040 class CrcErr : public Err {public: CrcErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: CRC check error") {}};
00041 class LengthErr : public Err {public: LengthErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: length check error") {}};
00042
00043
00044
00045
00046
00047 Gunzip(BufferedTransformation *attachment = NULL, bool repeat = false, int autoSignalPropagation = -1);
00048
00049 protected:
00050 enum {
00051
00052 MAGIC1=0x1f,
00053
00054 MAGIC2=0x8b,
00055
00056 DEFLATED=8
00057 };
00058
00059 enum FLAG_MASKS {
00060 CONTINUED=2, EXTRA_FIELDS=4, FILENAME=8, COMMENTS=16, ENCRYPTED=32};
00061
00062 unsigned int MaxPrestreamHeaderSize() const {return 1024;}
00063 void ProcessPrestreamHeader();
00064 void ProcessDecompressedData(const byte *string, size_t length);
00065 unsigned int MaxPoststreamTailSize() const {return 8;}
00066 void ProcessPoststreamTail();
00067
00068 word32 m_length;
00069 CRC32 m_crc;
00070 };
00071
00072 NAMESPACE_END
00073
00074 #endif