Crypto++
zlib.h
1 #ifndef CRYPTOPP_ZLIB_H
2 #define CRYPTOPP_ZLIB_H
3 
4 #include "adler32.h"
5 #include "zdeflate.h"
6 #include "zinflate.h"
7 
8 NAMESPACE_BEGIN(CryptoPP)
9 
10 /// ZLIB Compressor (RFC 1950)
11 class ZlibCompressor : public Deflator
12 {
13 public:
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 
21 protected:
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)
30 class ZlibDecompressor : public Inflator
31 {
32 public:
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 
45 private:
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 
56 NAMESPACE_END
57 
58 #endif
ZlibDecompressor(BufferedTransformation *attachment=NULL, bool repeat=false, int autoSignalPropagation=-1)
DEFLATE (RFC 1951) compressor.
Definition: zdeflate.h:55
interface for buffered transformations
Definition: cryptlib.h:770
data integerity check (such as CRC or MAC) failed
Definition: cryptlib.h:121
ADLER-32 checksum calculations.
Definition: adler32.h:9
received input data that doesn't conform to expected format
Definition: cryptlib.h:123
ZLIB Compressor (RFC 1950)
Definition: zlib.h:11
ZLIB Decompressor (RFC 1950)
Definition: zlib.h:30
DEFLATE (RFC 1951) decompressor.
Definition: zinflate.h:85
interface for retrieving values given their names
Definition: cryptlib.h:224