6#ifndef CRYPTOPP_ZINFLATE_H
7#define CRYPTOPP_ZINFLATE_H
17class LowFirstBitReader
21 : m_store(store), m_buffer(0), m_bitsBuffered(0) {}
22 unsigned int BitsBuffered()
const {
return m_bitsBuffered;}
23 unsigned long PeekBuffer()
const {
return m_buffer;}
24 bool FillBuffer(
unsigned int length);
25 unsigned long PeekBits(
unsigned int length);
26 void SkipBits(
unsigned int length);
27 unsigned long GetBits(
unsigned int length);
31 unsigned long m_buffer;
32 unsigned int m_bitsBuffered;
42 typedef unsigned int code_t;
43 typedef unsigned int value_t;
44 enum {MAX_CODE_BITS =
sizeof(code_t)*8};
48 HuffmanDecoder() : m_maxCodeBits(0), m_cacheBits(0), m_cacheMask(0), m_normalizedCacheMask(0) {}
49 HuffmanDecoder(
const unsigned int *codeBitLengths,
unsigned int nCodes)
50 : m_maxCodeBits(0), m_cacheBits(0), m_cacheMask(0), m_normalizedCacheMask(0)
51 {Initialize(codeBitLengths, nCodes);}
53 void Initialize(
const unsigned int *codeBitLengths,
unsigned int nCodes);
54 unsigned int Decode(code_t code, value_t &value)
const;
55 bool Decode(LowFirstBitReader &reader, value_t &value)
const;
58 friend struct CodeLessThan;
62 CodeInfo(code_t code=0,
unsigned int len=0, value_t value=0) : code(code), len(len), value(value) {}
63 inline bool operator<(
const CodeInfo &rhs)
const {
return code < rhs.code;}
75 const CodeInfo *begin;
84 static code_t NormalizeCode(code_t code,
unsigned int codeBits);
85 void FillCacheEntry(LookupEntry &entry, code_t normalizedCode)
const;
87 unsigned int m_maxCodeBits, m_cacheBits, m_cacheMask, m_normalizedCacheMask;
88 std::vector<CodeInfo, AllocatorWithCleanup<CodeInfo> > m_codeToValue;
89 mutable std::vector<LookupEntry, AllocatorWithCleanup<LookupEntry> > m_cache;
104 class UnexpectedEndErr :
public Err {
public: UnexpectedEndErr() : Err(
INVALID_DATA_FORMAT,
"Inflator: unexpected end of compressed block") {}};
106 class BadBlockErr :
public Err {
public: BadBlockErr() : Err(
INVALID_DATA_FORMAT,
"Inflator: error in compressed block") {}};
108 class BadDistanceErr :
public Err {
public: BadDistanceErr() : Err(
INVALID_DATA_FORMAT,
"Inflator: error in bit distance") {}};
117 size_t Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking);
120 virtual unsigned int GetLog2WindowSize()
const {
return 15;}
126 virtual unsigned int MaxPrestreamHeaderSize()
const {
return 0;}
127 virtual void ProcessPrestreamHeader() {}
128 virtual void ProcessDecompressedData(
const byte *
string,
size_t length)
130 virtual unsigned int MaxPoststreamTailSize()
const {
return 0;}
131 virtual void ProcessPoststreamTail() {}
133 void ProcessInput(
bool flush);
137 void OutputByte(
byte b);
138 void OutputString(
const byte *
string,
size_t length);
139 void OutputPast(
unsigned int length,
unsigned int distance);
141 void CreateFixedDistanceDecoder();
142 void CreateFixedLiteralDecoder();
144 const HuffmanDecoder& GetLiteralDecoder();
145 const HuffmanDecoder& GetDistanceDecoder();
147 enum State {PRE_STREAM, WAIT_HEADER, DECODING_BODY, POST_STREAM, AFTER_END};
149 bool m_repeat, m_eof, m_wrappedAround;
152 enum NextDecode {LITERAL, LENGTH_BITS, DISTANCE, DISTANCE_BITS};
153 NextDecode m_nextDecode;
154 unsigned int m_literal, m_distance;
155 HuffmanDecoder m_dynamicLiteralDecoder, m_dynamicDistanceDecoder;
156 member_ptr<HuffmanDecoder> m_fixedLiteralDecoder, m_fixedDistanceDecoder;
157 LowFirstBitReader m_reader;
158 SecByteBlock m_window;
159 size_t m_current, m_lastFlush;
AutoSignaling(int propagation=-1)
Data structure used to store byte strings.
Exception(ErrorType errorType, const std::string &s)
Construct a new Exception.
ErrorType
Error types or categories.
@ INVALID_DATA_FORMAT
Input data was received that did not conform to expected format.
const char * what() const
Retrieves a C-string describing the exception.
BufferedTransformation * AttachedTransformation()
Retrieve attached transformation.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
Inflator(BufferedTransformation *attachment=NULL, bool repeat=false, int autoSignalPropagation=-1)
RFC 1951 Decompressor.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
Interface for retrieving values given their names.
unsigned short word16
16-bit unsigned datatype
Abstract base classes that provide a uniform interface to this library.
Implementation of BufferedTransformation's attachment interface.
Crypto++ library namespace.
Classes and functions for secure memory allocations.