7NAMESPACE_BEGIN(CryptoPP)
10static inline bool Is8859Character(
char c) {
11 const unsigned char cc =
static_cast<unsigned char>(c);
12 return (cc >= 32 && cc <= 126) || (cc >= 160);
20 if (parameters.
GetValue(Name::FileName(), v))
21 m_filename.assign(
reinterpret_cast<const char*
>(v.
begin()), v.
size());
22 if (parameters.
GetValue(Name::Comment(), v))
23 m_comment.assign(
reinterpret_cast<const char*
>(v.
begin()), v.
size());
27void Gzip::WritePrestreamHeader()
33 if(!m_filename.empty())
35 if(!m_comment.empty())
49 if(!m_filename.empty())
53 if(!m_comment.empty())
57void Gzip::ProcessUncompressedData(
const byte *inString,
size_t length)
59 m_crc.
Update(inString, length);
60 m_totalLen += (
word32)length;
63void Gzip::WritePoststreamTail()
77 if(throwOnEncodingError)
79 for(
size_t i = 0; i < comment.length(); i++) {
80 const char c = comment[i];
81 if(!Is8859Character(c))
91 if(throwOnEncodingError)
93 for(
size_t i = 0; i < filename.length(); i++) {
94 const char c = filename[i];
95 if(!Is8859Character(c))
100 m_filename = filename;
106 :
Inflator(attachment, repeat, propagation), m_length(0), m_filetime(0)
110void Gunzip::ProcessPrestreamHeader()
122 if (m_inQueue.
Get(buf, 2)!=2)
throw HeaderErr();
123 if (buf[0] !=
MAGIC1 || buf[1] !=
MAGIC2)
throw HeaderErr();
124 if (!m_inQueue.
Get(b) || (b !=
DEFLATED))
throw HeaderErr();
125 if (!m_inQueue.
Get(flags))
throw HeaderErr();
126 if (flags & (ENCRYPTED | CONTINUED))
throw HeaderErr();
127 if (m_inQueue.
GetWord32(m_filetime, LITTLE_ENDIAN_ORDER) != 4)
throw HeaderErr();
128 if (m_inQueue.
Skip(2)!=2)
throw HeaderErr();
130 if (flags & EXTRA_FIELDS)
133 if (m_inQueue.
GetWord16(length, LITTLE_ENDIAN_ORDER) != 2)
throw HeaderErr();
134 if (m_inQueue.
Skip(length)!=length)
throw HeaderErr();
137 if (flags & FILENAME)
141 if(!m_inQueue.
Get(b))
throw HeaderErr();
142 if(b) m_filename.append( 1, (
char)b );
147 if (flags & COMMENTS)
151 if(!m_inQueue.
Get(b))
throw HeaderErr();
152 if(b) m_comment.append( 1, (
char)b );
158void Gunzip::ProcessDecompressedData(
const byte *inString,
size_t length)
161 m_crc.
Update(inString, length);
162 m_length += (
word32)length;
165void Gunzip::ProcessPoststreamTail()
168 if (m_inQueue.
Get(crc, 4) != 4)
174 if (m_inQueue.
GetWord32(lengthCheck, LITTLE_ENDIAN_ORDER) != 4)
176 if (lengthCheck != m_length)
182 if(throwOnEncodingError)
184 for(
size_t i = 0; i < m_comment.length(); i++) {
185 const char c = m_comment[i];
186 if(!Is8859Character(c))
196 if(throwOnEncodingError)
198 for(
size_t i = 0; i < m_filename.length(); i++) {
199 const char c = m_filename[i];
200 if(!Is8859Character(c))
Standard names for retrieving values by name when working with NameValuePairs.
size_t Get(byte &outByte)
Retrieve a 8-bit byte.
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Used to pass byte array input as part of a NameValuePairs object.
const byte * begin() const
Pointer to the first byte in the memory block.
size_t size() const
Length of the memory block.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
int GetDeflateLevel() const
Retrieves the deflation level.
BufferedTransformation * AttachedTransformation()
Retrieve attached transformation.
@ MAGIC1
First header magic value.
@ MAGIC2
Second header magic value.
const std::string & GetComment(bool throwOnEncodingError=false) const
const std::string & GetFilename(bool throwOnEncodingError=false) const
Gunzip(BufferedTransformation *attachment=NULLPTR, bool repeat=false, int autoSignalPropagation=-1)
Construct a Gunzip decompressor.
void SetComment(const std::string &comment, bool throwOnEncodingError=false)
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
void SetFilename(const std::string &filename, bool throwOnEncodingError=false)
DEFLATE decompressor (RFC 1951)
Interface for retrieving values given their names.
bool GetValue(const char *name, T &value) const
Get a named value.
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
unsigned int word32
32-bit unsigned datatype
unsigned short word16
16-bit unsigned datatype
GZIP compression and decompression (RFC 1952)