Security Scol plugin
gzip.h
Go to the documentation of this file.
1// gzip.h - originally written and placed in the public domain by Wei Dai
2
5
6#ifndef CRYPTOPP_GZIP_H
7#define CRYPTOPP_GZIP_H
8
9#include "cryptlib.h"
10#include "zdeflate.h"
11#include "zinflate.h"
12#include "crc.h"
13
14NAMESPACE_BEGIN(CryptoPP)
15
16
17class Gzip : public Deflator
18{
19public:
28 Gzip(BufferedTransformation *attachment=NULLPTR, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true)
29 : Deflator(attachment, deflateLevel, log2WindowSize, detectUncompressible), m_totalLen(0), m_filetime(0) { }
30
35 Gzip(const NameValuePairs &parameters, BufferedTransformation *attachment=NULLPTR)
36 : Deflator(parameters, attachment), m_totalLen(0), m_filetime(0)
37 {
38 IsolatedInitialize(parameters);
39 }
40
42 void SetFiletime(word32 filetime) { m_filetime = filetime; }
43
49 void SetFilename(const std::string& filename, bool throwOnEncodingError = false);
50
56 void SetComment(const std::string& comment, bool throwOnEncodingError = false);
57
58 void IsolatedInitialize(const NameValuePairs &parameters);
59
60protected:
61 enum {MAGIC1=0x1f, MAGIC2=0x8b, // flags for the header
62 DEFLATED=8, FAST=4, SLOW=2};
63
64 enum FLAG_MASKS {
65 FILENAME=8, COMMENTS=16};
66
67 void WritePrestreamHeader();
68 void ProcessUncompressedData(const byte *string, size_t length);
69 void WritePoststreamTail();
70
71 word32 m_totalLen;
72 CRC32 m_crc;
73
74 word32 m_filetime;
75 std::string m_filename;
76 std::string m_comment;
77};
78
80class Gunzip : public Inflator
81{
82public:
83 typedef Inflator::Err Err;
84
86 class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "Gunzip: header decoding error") {}};
88 class TailErr : public Err {public: TailErr() : Err(INVALID_DATA_FORMAT, "Gunzip: tail too short") {}};
90 class CrcErr : public Err {public: CrcErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: CRC check error") {}};
92 class LengthErr : public Err {public: LengthErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: length check error") {}};
93
98 Gunzip(BufferedTransformation *attachment = NULLPTR, bool repeat = false, int autoSignalPropagation = -1);
99
101 word32 GetFiletime() const { return m_filetime; }
102
107 const std::string& GetFilename(bool throwOnEncodingError = false) const;
108
113 const std::string& GetComment(bool throwOnEncodingError = false) const;
114
115protected:
116 enum {
118 MAGIC1=0x1f,
120 MAGIC2=0x8b,
122 DEFLATED=8
123 };
124
125 enum FLAG_MASKS {
126 CONTINUED=2, EXTRA_FIELDS=4, FILENAME=8, COMMENTS=16, ENCRYPTED=32};
127
128 unsigned int MaxPrestreamHeaderSize() const {return 1024;}
129 void ProcessPrestreamHeader();
130 void ProcessDecompressedData(const byte *string, size_t length);
131 unsigned int MaxPoststreamTailSize() const {return 8;}
132 void ProcessPoststreamTail();
133
134 word32 m_length;
135 CRC32 m_crc;
136
137 word32 m_filetime;
138 std::string m_filename;
139 std::string m_comment;
140};
141
142NAMESPACE_END
143
144#endif
Interface for buffered transformations.
Definition cryptlib.h:1652
CRC-32 Checksum Calculation.
Definition crc.h:26
DEFLATE compressor (RFC 1951)
Definition zdeflate.h:76
@ INVALID_DATA_FORMAT
Input data was received that did not conform to expected format.
Definition cryptlib.h:173
@ DATA_INTEGRITY_CHECK_FAILED
Data integerity check, such as CRC or MAC, failed.
Definition cryptlib.h:171
Exception thrown when a CRC error occurs.
Definition gzip.h:90
Exception thrown when a header decoding error occurs.
Definition gzip.h:86
Exception thrown when a length error occurs.
Definition gzip.h:92
Exception thrown when the tail is too short.
Definition gzip.h:88
GZIP Decompression (RFC 1952)
Definition gzip.h:81
@ DEFLATED
Deflated flag.
Definition gzip.h:122
@ MAGIC1
First header magic value.
Definition gzip.h:118
@ MAGIC2
Second header magic value.
Definition gzip.h:120
word32 GetFiletime() const
Definition gzip.h:101
const std::string & GetComment(bool throwOnEncodingError=false) const
Definition gzip.cpp:180
const std::string & GetFilename(bool throwOnEncodingError=false) const
Definition gzip.cpp:194
GZIP Compression (RFC 1952)
Definition gzip.h:18
void SetFiletime(word32 filetime)
Definition gzip.h:42
Gzip(BufferedTransformation *attachment=NULLPTR, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true)
Construct a Gzip compressor.
Definition gzip.h:28
Gzip(const NameValuePairs &parameters, BufferedTransformation *attachment=NULLPTR)
Construct a Gzip compressor.
Definition gzip.h:35
DEFLATE decompressor (RFC 1951)
Definition zinflate.h:95
Interface for retrieving values given their names.
Definition cryptlib.h:322
unsigned int word32
32-bit unsigned datatype
Definition config_int.h:62
Classes for CRC-32 and CRC-32C checksum algorithm.
Abstract base classes that provide a uniform interface to this library.
DEFLATE compression and decompression (RFC 1951)
DEFLATE compression and decompression (RFC 1951)