📄 zlib_8cpp-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Crypto++: zlib.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div><h1>zlib.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// zlib.cpp - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="comment">// "zlib" is the name of a well known C language compression library</span>00004 <span class="comment">// (http://www.zlib.org) and also the name of a compression format</span>00005 <span class="comment">// (RFC 1950) that the library implements. This file is part of a</span>00006 <span class="comment">// complete reimplementation of the zlib compression format.</span>00007 00008 <span class="preprocessor">#include "pch.h"</span>00009 <span class="preprocessor">#include "zlib.h"</span>00010 <span class="preprocessor">#include "zdeflate.h"</span>00011 <span class="preprocessor">#include "zinflate.h"</span>00012 00013 NAMESPACE_BEGIN(CryptoPP)00014 00015 <span class="keyword">static</span> <span class="keyword">const</span> byte DEFLATE_METHOD = 8;00016 <span class="keyword">static</span> <span class="keyword">const</span> byte FDICT_FLAG = 1 << 5;00017 00018 <span class="comment">// *************************************************************</span>00019 00020 <span class="keywordtype">void</span> ZlibCompressor::WritePrestreamHeader()00021 {00022 m_adler32.<a class="code" href="class_hash_transformation.html#_x_m_a_c_ca8">Restart</a>();00023 byte cmf = DEFLATE_METHOD | ((GetLog2WindowSize()-8) << 4);00024 byte flags = GetCompressionLevel() << 6;00025 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_2">PutWord16</a>(RoundUpToMultipleOf(cmf*256+flags, 31));00026 }00027 00028 <span class="keywordtype">void</span> ZlibCompressor::ProcessUncompressedData(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00029 {00030 m_adler32.<a class="code" href="class_adler32.html#_adler32a1">Update</a>(inString, length);00031 }00032 00033 <span class="keywordtype">void</span> ZlibCompressor::WritePoststreamTail()00034 {00035 FixedSizeSecBlock<byte, 4> adler32;00036 m_adler32.<a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea13">Final</a>(adler32);00037 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(adler32, 4);00038 }00039 00040 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ZlibCompressor::GetCompressionLevel()<span class="keyword"> const</span>00041 <span class="keyword"></span>{00042 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> deflateToCompressionLevel[] = {0, 1, 1, 1, 2, 2, 2, 2, 2, 3};00043 <span class="keywordflow">return</span> deflateToCompressionLevel[GetDeflateLevel()];00044 }00045 00046 <span class="comment">// *************************************************************</span>00047 <a name="l00048"></a><a class="code" href="class_zlib_decompressor.html#_zlib_decompressora0">00048</a> <a class="code" href="class_zlib_decompressor.html#_zlib_decompressora0">ZlibDecompressor::ZlibDecompressor</a>(<a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment, <span class="keywordtype">bool</span> repeat, <span class="keywordtype">int</span> propagation)00049 : <a class="code" href="class_inflator.html">Inflator</a>(attachment, repeat, propagation)00050 {00051 }00052 00053 <span class="keywordtype">void</span> ZlibDecompressor::ProcessPrestreamHeader()00054 {00055 m_adler32.<a class="code" href="class_hash_transformation.html#_x_m_a_c_ca8">Restart</a>();00056 00057 byte cmf;00058 byte flags;00059 00060 <span class="keywordflow">if</span> (!m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera8">Get</a>(cmf) || !m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera8">Get</a>(flags))00061 <span class="keywordflow">throw</span> HeaderErr();00062 00063 <span class="keywordflow">if</span> ((cmf*256+flags) % 31 != 0)00064 <span class="keywordflow">throw</span> HeaderErr(); <span class="comment">// if you hit this exception, you're probably trying to decompress invalid data</span>00065 00066 <span class="keywordflow">if</span> ((cmf & 0xf) != DEFLATE_METHOD)00067 <span class="keywordflow">throw</span> UnsupportedAlgorithm();00068 00069 <span class="keywordflow">if</span> (flags & FDICT_FLAG)00070 <span class="keywordflow">throw</span> UnsupportedPresetDictionary();00071 00072 m_log2WindowSize = 8 + (cmf >> 4);00073 }00074 00075 <span class="keywordtype">void</span> ZlibDecompressor::ProcessDecompressedData(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00076 {00077 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(inString, length);00078 m_adler32.<a class="code" href="class_adler32.html#_adler32a1">Update</a>(inString, length);00079 }00080 00081 <span class="keywordtype">void</span> ZlibDecompressor::ProcessPoststreamTail()00082 {00083 FixedSizeSecBlock<byte, 4> adler32;00084 <span class="keywordflow">if</span> (m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera8">Get</a>(adler32, 4) != 4)00085 <span class="keywordflow">throw</span> Adler32Err();00086 <span class="keywordflow">if</span> (!m_adler32.<a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea15">Verify</a>(adler32))00087 <span class="keywordflow">throw</span> Adler32Err();00088 }00089 00090 NAMESPACE_END</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:29 2003 for Crypto++ by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -