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.

74 lines
2.4 KiB

  1. #ifndef CRYPTOPP_GZIP_H
  2. #define CRYPTOPP_GZIP_H
  3. #include "cryptlib.h"
  4. #include "zdeflate.h"
  5. #include "zinflate.h"
  6. #include "crc.h"
  7. NAMESPACE_BEGIN(CryptoPP)
  8. /// GZIP Compression (RFC 1952)
  9. class Gzip : public Deflator
  10. {
  11. public:
  12. Gzip(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), m_totalLen(0) {}
  14. Gzip(const NameValuePairs &parameters, BufferedTransformation *attachment=NULL)
  15. : Deflator(parameters, attachment), m_totalLen(0) {}
  16. protected:
  17. enum {MAGIC1=0x1f, MAGIC2=0x8b, // flags for the header
  18. DEFLATED=8, FAST=4, SLOW=2};
  19. void WritePrestreamHeader();
  20. void ProcessUncompressedData(const byte *string, size_t length);
  21. void WritePoststreamTail();
  22. word32 m_totalLen;
  23. CRC32 m_crc;
  24. };
  25. //! \class Gunzip
  26. //! \brief GZIP Decompression (RFC 1952)
  27. class Gunzip : public Inflator
  28. {
  29. public:
  30. typedef Inflator::Err Err;
  31. class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "Gunzip: header decoding error") {}};
  32. class TailErr : public Err {public: TailErr() : Err(INVALID_DATA_FORMAT, "Gunzip: tail too short") {}};
  33. class CrcErr : public Err {public: CrcErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: CRC check error") {}};
  34. class LengthErr : public Err {public: LengthErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: length check error") {}};
  35. //! \brief Construct a Gunzip
  36. //! \param attachment a \ BufferedTransformation to attach to this object
  37. //! \param repeat decompress multiple compressed streams in series
  38. //! \param autoSignalPropagation 0 to turn off MessageEnd signal
  39. Gunzip(BufferedTransformation *attachment = NULL, bool repeat = false, int autoSignalPropagation = -1);
  40. protected:
  41. enum {
  42. //! \brief First header magic value
  43. MAGIC1=0x1f,
  44. //! \brief Second header magic value
  45. MAGIC2=0x8b,
  46. //! \brief Deflated flag
  47. DEFLATED=8
  48. };
  49. enum FLAG_MASKS {
  50. CONTINUED=2, EXTRA_FIELDS=4, FILENAME=8, COMMENTS=16, ENCRYPTED=32};
  51. unsigned int MaxPrestreamHeaderSize() const {return 1024;}
  52. void ProcessPrestreamHeader();
  53. void ProcessDecompressedData(const byte *string, size_t length);
  54. unsigned int MaxPoststreamTailSize() const {return 8;}
  55. void ProcessPoststreamTail();
  56. word32 m_length;
  57. CRC32 m_crc;
  58. };
  59. NAMESPACE_END
  60. #endif