Crypto++  5.6.3
Free C++ class library of cryptographic schemes
gzip.h
1 #ifndef CRYPTOPP_GZIP_H
2 #define CRYPTOPP_GZIP_H
3 
4 #include "cryptlib.h"
5 #include "zdeflate.h"
6 #include "zinflate.h"
7 #include "crc.h"
8 
9 NAMESPACE_BEGIN(CryptoPP)
10 
11 /// GZIP Compression (RFC 1952)
12 class Gzip : public Deflator
13 {
14 public:
15  Gzip(BufferedTransformation *attachment=NULL, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true)
16  : Deflator(attachment, deflateLevel, log2WindowSize, detectUncompressible), m_totalLen(0) {}
17  Gzip(const NameValuePairs &parameters, BufferedTransformation *attachment=NULL)
18  : Deflator(parameters, attachment), m_totalLen(0) {}
19 
20 protected:
21  enum {MAGIC1=0x1f, MAGIC2=0x8b, // flags for the header
22  DEFLATED=8, FAST=4, SLOW=2};
23 
24  void WritePrestreamHeader();
25  void ProcessUncompressedData(const byte *string, size_t length);
26  void WritePoststreamTail();
27 
28  word32 m_totalLen;
29  CRC32 m_crc;
30 };
31 
32 //! \class Gunzip
33 //! \brief GZIP Decompression (RFC 1952)
34 class Gunzip : public Inflator
35 {
36 public:
37  typedef Inflator::Err Err;
38  class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "Gunzip: header decoding error") {}};
39  class TailErr : public Err {public: TailErr() : Err(INVALID_DATA_FORMAT, "Gunzip: tail too short") {}};
40  class CrcErr : public Err {public: CrcErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: CRC check error") {}};
41  class LengthErr : public Err {public: LengthErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: length check error") {}};
42 
43  //! \brief Construct a Gunzip
44  //! \param attachment a \ BufferedTransformation to attach to this object
45  //! \param repeat decompress multiple compressed streams in series
46  //! \param autoSignalPropagation 0 to turn off MessageEnd signal
47  Gunzip(BufferedTransformation *attachment = NULL, bool repeat = false, int autoSignalPropagation = -1);
48 
49 protected:
50  enum {
51  //! \brief First header magic value
52  MAGIC1=0x1f,
53  //! \brief Second header magic value
54  MAGIC2=0x8b,
55  //! \brief Deflated flag
56  DEFLATED=8
57  };
58 
59  enum FLAG_MASKS {
60  CONTINUED=2, EXTRA_FIELDS=4, FILENAME=8, COMMENTS=16, ENCRYPTED=32};
61 
62  unsigned int MaxPrestreamHeaderSize() const {return 1024;}
63  void ProcessPrestreamHeader();
64  void ProcessDecompressedData(const byte *string, size_t length);
65  unsigned int MaxPoststreamTailSize() const {return 8;}
66  void ProcessPoststreamTail();
67 
68  word32 m_length;
69  CRC32 m_crc;
70 };
71 
72 NAMESPACE_END
73 
74 #endif
GZIP Decompression (RFC 1952)
Definition: gzip.h:34
Abstract base classes that provide a uniform interface to this library.
DEFLATE (RFC 1951) compressor.
Definition: zdeflate.h:65
Classes for CRC-32 checksum algorithm.
Interface for buffered transformations.
Definition: cryptlib.h:1342
Data integerity check, such as CRC or MAC, failed.
Definition: cryptlib.h:152
Gunzip(BufferedTransformation *attachment=NULL, bool repeat=false, int autoSignalPropagation=-1)
Construct a Gunzip.
Definition: gzip.cpp:39
Input data was received that did not conform to expected format.
Definition: cryptlib.h:154
DEFLATE (RFC 1951) decompressor.
Definition: zinflate.h:88
Crypto++ library namespace.
GZIP Compression (RFC 1952)
Definition: gzip.h:12
CRC Checksum Calculation.
Definition: crc.h:25
Interface for retrieving values given their names.
Definition: cryptlib.h:277