Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.3 KiB

  1. #ifndef CRYPTOPP_ZLIB_H
  2. #define CRYPTOPP_ZLIB_H
  3. #include "cryptlib.h"
  4. #include "adler32.h"
  5. #include "zdeflate.h"
  6. #include "zinflate.h"
  7. NAMESPACE_BEGIN(CryptoPP)
  8. /// ZLIB Compressor (RFC 1950)
  9. class ZlibCompressor : public Deflator
  10. {
  11. public:
  12. ZlibCompressor(BufferedTransformation *attachment=NULL, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true)
  13. : Deflator(attachment, deflateLevel, log2WindowSize, detectUncompressible) {}
  14. ZlibCompressor(const NameValuePairs &parameters, BufferedTransformation *attachment=NULL)
  15. : Deflator(parameters, attachment) {}
  16. unsigned int GetCompressionLevel() const;
  17. protected:
  18. void WritePrestreamHeader();
  19. void ProcessUncompressedData(const byte *string, size_t length);
  20. void WritePoststreamTail();
  21. Adler32 m_adler32;
  22. };
  23. /// ZLIB Decompressor (RFC 1950)
  24. class ZlibDecompressor : public Inflator
  25. {
  26. public:
  27. typedef Inflator::Err Err;
  28. class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: header decoding error") {}};
  29. class Adler32Err : public Err {public: Adler32Err() : Err(DATA_INTEGRITY_CHECK_FAILED, "ZlibDecompressor: ADLER32 check error") {}};
  30. class UnsupportedAlgorithm : public Err {public: UnsupportedAlgorithm() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: unsupported algorithm") {}};
  31. class UnsupportedPresetDictionary : public Err {public: UnsupportedPresetDictionary() : Err(INVALID_DATA_FORMAT, "ZlibDecompressor: unsupported preset dictionary") {}};
  32. //! \brief Construct a ZlibDecompressor
  33. //! \param attachment a \ BufferedTransformation to attach to this object
  34. //! \param repeat decompress multiple compressed streams in series
  35. //! \param autoSignalPropagation 0 to turn off MessageEnd signal
  36. ZlibDecompressor(BufferedTransformation *attachment = NULL, bool repeat = false, int autoSignalPropagation = -1);
  37. unsigned int GetLog2WindowSize() const {return m_log2WindowSize;}
  38. private:
  39. unsigned int MaxPrestreamHeaderSize() const {return 2;}
  40. void ProcessPrestreamHeader();
  41. void ProcessDecompressedData(const byte *string, size_t length);
  42. unsigned int MaxPoststreamTailSize() const {return 4;}
  43. void ProcessPoststreamTail();
  44. unsigned int m_log2WindowSize;
  45. Adler32 m_adler32;
  46. };
  47. NAMESPACE_END
  48. #endif