⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zlib_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>Crypto++: zlib.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.2 --><div class="tabs">  <ul>    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>    <li><a href="namespaces.html"><span>Namespaces</span></a></li>    <li><a href="classes.html"><span>Classes</span></a></li>    <li class="current"><a href="files.html"><span>Files</span></a></li>  </ul></div><div class="tabs">  <ul>    <li><a href="files.html"><span>File&nbsp;List</span></a></li>    <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>  </ul></div><h1>zlib.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// zlib.cpp - written and placed in the public domain by Wei Dai</span><a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="comment">// "zlib" is the name of a well known C language compression library</span><a name="l00004"></a>00004 <span class="comment">// (http://www.zlib.org) and also the name of a compression format</span><a name="l00005"></a>00005 <span class="comment">// (RFC 1950) that the library implements. This file is part of a</span><a name="l00006"></a>00006 <span class="comment">// complete reimplementation of the zlib compression format.</span><a name="l00007"></a>00007 <a name="l00008"></a>00008 <span class="preprocessor">#include "pch.h"</span><a name="l00009"></a>00009 <span class="preprocessor">#include "zlib.h"</span><a name="l00010"></a>00010 <span class="preprocessor">#include "zdeflate.h"</span><a name="l00011"></a>00011 <span class="preprocessor">#include "zinflate.h"</span><a name="l00012"></a>00012 <a name="l00013"></a>00013 NAMESPACE_BEGIN(CryptoPP)<a name="l00014"></a>00014 <a name="l00015"></a>00015 static const byte DEFLATE_METHOD = 8;<a name="l00016"></a>00016 static const byte FDICT_FLAG = 1 &lt;&lt; 5;<a name="l00017"></a>00017 <a name="l00018"></a>00018 <span class="comment">// *************************************************************</span><a name="l00019"></a>00019 <a name="l00020"></a><a class="code" href="class_zlib_compressor.html#053a7c18dc97d944c0a0fabd1bdea5d4">00020</a> <span class="keywordtype">void</span> <a class="code" href="class_zlib_compressor.html" title="ZLIB Compressor (RFC 1950).">ZlibCompressor</a>::WritePrestreamHeader()<a name="l00021"></a>00021 {<a name="l00022"></a>00022         m_adler32.Restart();<a name="l00023"></a>00023         byte cmf = DEFLATE_METHOD | ((GetLog2WindowSize()-8) &lt;&lt; 4);<a name="l00024"></a>00024         byte flags = GetCompressionLevel() &lt;&lt; 6;<a name="l00025"></a>00025         AttachedTransformation()-&gt;PutWord16(RoundUpToMultipleOf(cmf*256+flags, 31));<a name="l00026"></a>00026 }<a name="l00027"></a>00027 <a name="l00028"></a><a class="code" href="class_zlib_compressor.html#ed54d55ae161ce412d9f8ec55df3a33a">00028</a> <span class="keywordtype">void</span> <a class="code" href="class_zlib_compressor.html#ed54d55ae161ce412d9f8ec55df3a33a">ZlibCompressor::ProcessUncompressedData</a>(<span class="keyword">const</span> byte *inString, <span class="keywordtype">size_t</span> length)<a name="l00029"></a>00029 {<a name="l00030"></a>00030         <a class="code" href="class_zlib_compressor.html#9abfa9dafca53bd2e1368a591191dba2">m_adler32</a>.<a class="code" href="class_adler32.html#84c3d47f039beab76b5f902ff558ac49" title="process more input">Update</a>(inString, length);<a name="l00031"></a>00031 }<a name="l00032"></a>00032 <a name="l00033"></a><a class="code" href="class_zlib_compressor.html#6beedf943b7d0466dfc4d13d0a1f7adf">00033</a> <span class="keywordtype">void</span> <a class="code" href="class_zlib_compressor.html#6beedf943b7d0466dfc4d13d0a1f7adf">ZlibCompressor::WritePoststreamTail</a>()<a name="l00034"></a>00034 {<a name="l00035"></a>00035         <a class="code" href="class_fixed_size_sec_block.html" title="a SecBlock with fixed size, allocated statically">FixedSizeSecBlock&lt;byte, 4&gt;</a> adler32;<a name="l00036"></a>00036         <a class="code" href="class_zlib_compressor.html#9abfa9dafca53bd2e1368a591191dba2">m_adler32</a>.<a class="code" href="class_hash_transformation.html#a0b8c7a110d8968268fd02ec32b9a8e8" title="compute hash for current message, then restart for a new message">Final</a>(adler32);<a name="l00037"></a>00037         <a class="code" href="class_filter.html#c8fc888888b2dad88bf64fc703044a93" title="returns the object immediately attached to this object or NULL for no attachment">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#e70658b0d271f8e114ac6c3cc9774ede" title="input a byte for processing">Put</a>(adler32, 4);<a name="l00038"></a>00038 }<a name="l00039"></a>00039 <a name="l00040"></a><a class="code" href="class_zlib_compressor.html#f0b1f600f1e2d81975dfc14ed98aaeb8">00040</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_zlib_compressor.html#f0b1f600f1e2d81975dfc14ed98aaeb8">ZlibCompressor::GetCompressionLevel</a>()<span class="keyword"> const</span><a name="l00041"></a>00041 <span class="keyword"></span>{<a name="l00042"></a>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};<a name="l00043"></a>00043         <span class="keywordflow">return</span> deflateToCompressionLevel[<a class="code" href="class_deflator.html#d2ecf9c16317cef8b68fbbcca705e0a4">GetDeflateLevel</a>()];<a name="l00044"></a>00044 }<a name="l00045"></a>00045 <a name="l00046"></a>00046 <span class="comment">// *************************************************************</span><a name="l00047"></a>00047 <a name="l00048"></a><a class="code" href="class_zlib_decompressor.html#2811c881df0f9cd29a8a047c12c3a744">00048</a> <a class="code" href="class_zlib_decompressor.html#2811c881df0f9cd29a8a047c12c3a744">ZlibDecompressor::ZlibDecompressor</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> *attachment, <span class="keywordtype">bool</span> repeat, <span class="keywordtype">int</span> propagation)<a name="l00049"></a>00049         : <a class="code" href="class_inflator.html" title="DEFLATE (RFC 1951) decompressor.">Inflator</a>(attachment, repeat, propagation)<a name="l00050"></a>00050 {<a name="l00051"></a>00051 }<a name="l00052"></a>00052 <a name="l00053"></a>00053 <span class="keywordtype">void</span> ZlibDecompressor::ProcessPrestreamHeader()<a name="l00054"></a>00054 {<a name="l00055"></a>00055         m_adler32.<a class="code" href="class_hash_transformation.html#92752eebac10497211d7a065faba8725" title="discard the current state, and restart with a new message">Restart</a>();<a name="l00056"></a>00056 <a name="l00057"></a>00057         byte cmf;<a name="l00058"></a>00058         byte flags;<a name="l00059"></a>00059 <a name="l00060"></a>00060         <span class="keywordflow">if</span> (!<a class="code" href="class_inflator.html#e219ede9a3c7342d6c9262f87c8a571d">m_inQueue</a>.<a class="code" href="class_byte_queue.html#19413e3aa72b749e3771d617e8eca632" title="try to retrieve a single byte">Get</a>(cmf) || !<a class="code" href="class_inflator.html#e219ede9a3c7342d6c9262f87c8a571d">m_inQueue</a>.<a class="code" href="class_byte_queue.html#19413e3aa72b749e3771d617e8eca632" title="try to retrieve a single byte">Get</a>(flags))<a name="l00061"></a>00061                 <span class="keywordflow">throw</span> HeaderErr();<a name="l00062"></a>00062 <a name="l00063"></a>00063         <span class="keywordflow">if</span> ((cmf*256+flags) % 31 != 0)<a name="l00064"></a>00064                 <span class="keywordflow">throw</span> HeaderErr();      <span class="comment">// if you hit this exception, you're probably trying to decompress invalid data</span><a name="l00065"></a>00065 <a name="l00066"></a>00066         <span class="keywordflow">if</span> ((cmf &amp; 0xf) != DEFLATE_METHOD)<a name="l00067"></a>00067                 <span class="keywordflow">throw</span> UnsupportedAlgorithm();<a name="l00068"></a>00068 <a name="l00069"></a>00069         <span class="keywordflow">if</span> (flags &amp; FDICT_FLAG)<a name="l00070"></a>00070                 <span class="keywordflow">throw</span> UnsupportedPresetDictionary();<a name="l00071"></a>00071 <a name="l00072"></a>00072         m_log2WindowSize = 8 + (cmf &gt;&gt; 4);<a name="l00073"></a>00073 }<a name="l00074"></a>00074 <a name="l00075"></a>00075 <span class="keywordtype">void</span> ZlibDecompressor::ProcessDecompressedData(<span class="keyword">const</span> byte *inString, <span class="keywordtype">size_t</span> length)<a name="l00076"></a>00076 {<a name="l00077"></a>00077         <a class="code" href="class_filter.html#c8fc888888b2dad88bf64fc703044a93" title="returns the object immediately attached to this object or NULL for no attachment">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#e70658b0d271f8e114ac6c3cc9774ede" title="input a byte for processing">Put</a>(inString, length);<a name="l00078"></a>00078         m_adler32.<a class="code" href="class_adler32.html#84c3d47f039beab76b5f902ff558ac49" title="process more input">Update</a>(inString, length);<a name="l00079"></a>00079 }<a name="l00080"></a>00080 <a name="l00081"></a>00081 <span class="keywordtype">void</span> ZlibDecompressor::ProcessPoststreamTail()<a name="l00082"></a>00082 {<a name="l00083"></a>00083         <a class="code" href="class_fixed_size_sec_block.html" title="a SecBlock with fixed size, allocated statically">FixedSizeSecBlock&lt;byte, 4&gt;</a> adler32;<a name="l00084"></a>00084         <span class="keywordflow">if</span> (<a class="code" href="class_inflator.html#e219ede9a3c7342d6c9262f87c8a571d">m_inQueue</a>.<a class="code" href="class_byte_queue.html#19413e3aa72b749e3771d617e8eca632" title="try to retrieve a single byte">Get</a>(adler32, 4) != 4)<a name="l00085"></a>00085                 <span class="keywordflow">throw</span> Adler32Err();<a name="l00086"></a>00086         <span class="keywordflow">if</span> (!m_adler32.<a class="code" href="class_hash_transformation.html#16c4aecd047015d513feef4ed5b929ba" title="verify that digest is a valid digest for the current message, then reinitialize the...">Verify</a>(adler32))<a name="l00087"></a>00087                 <span class="keywordflow">throw</span> Adler32Err();<a name="l00088"></a>00088 }<a name="l00089"></a>00089 <a name="l00090"></a>00090 NAMESPACE_END</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Fri Jun 1 11:11:26 2007 for Crypto++ by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.2 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -