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

📄 gzip_8cpp-source.html

📁 Crypto++是一个非常强大的密码学库,主要是功能全
💻 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++: gzip.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&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Compound&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Compound&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div><h1>gzip.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// gzip.cpp - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#include "pch.h"</span>00004 <span class="preprocessor">#include "gzip.h"</span>00005 00006 NAMESPACE_BEGIN(CryptoPP)00007 00008 <span class="keywordtype">void</span> Gzip::WritePrestreamHeader()00009 {00010         m_totalLen = 0;00011         m_crc.<a class="code" href="class_hash_transformation.html#_x_m_a_c_ca8">Restart</a>();00012 00013         <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(MAGIC1);00014         <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(MAGIC2);00015         <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(DEFLATED);00016         <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(0);               <span class="comment">// general flag</span>00017         <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_3">PutWord32</a>(0); <span class="comment">// time stamp</span>00018         byte extra = (GetDeflateLevel() == 1) ? FAST : ((GetDeflateLevel() == 9) ? SLOW : 0);00019         <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(extra);00020         <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(GZIP_OS_CODE);00021 }00022 00023 <span class="keywordtype">void</span> Gzip::ProcessUncompressedData(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00024 {00025         m_crc.<a class="code" href="class_c_r_c32.html#_c_r_c32a1">Update</a>(inString, length);00026         m_totalLen += length;00027 }00028 00029 <span class="keywordtype">void</span> Gzip::WritePoststreamTail()00030 {00031         <a class="code" href="class_sec_block.html">SecByteBlock</a> crc(4);00032         m_crc.<a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea13">Final</a>(crc);00033         <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(crc, 4);00034         <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_3">PutWord32</a>(m_totalLen, LITTLE_ENDIAN_ORDER);00035 }00036 00037 <span class="comment">// *************************************************************</span>00038 <a name="l00039"></a><a class="code" href="class_gunzip.html#_gunzipa0">00039</a> <a class="code" href="class_gunzip.html#_gunzipa0">Gunzip::Gunzip</a>(<a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment, <span class="keywordtype">bool</span> repeat, <span class="keywordtype">int</span> propagation)00040         : <a class="code" href="class_inflator.html">Inflator</a>(attachment, repeat, propagation)00041 {00042 }00043 00044 <span class="keywordtype">void</span> Gunzip::ProcessPrestreamHeader()00045 {00046         m_length = 0;00047         m_crc.<a class="code" href="class_hash_transformation.html#_x_m_a_c_ca8">Restart</a>();00048 00049         byte buf[6];00050         byte b, flags;00051 00052         <span class="keywordflow">if</span> (m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera8">Get</a>(buf, 2)!=2) <span class="keywordflow">throw</span> HeaderErr();00053         <span class="keywordflow">if</span> (buf[0] != MAGIC1 || buf[1] != MAGIC2) <span class="keywordflow">throw</span> HeaderErr();00054         <span class="keywordflow">if</span> (!m_inQueue.<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz7_11">Skip</a>(1)) <span class="keywordflow">throw</span> HeaderErr();       <span class="comment">// skip extra flags</span>00055         <span class="keywordflow">if</span> (!m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera8">Get</a>(flags)) <span class="keywordflow">throw</span> HeaderErr();00056         <span class="keywordflow">if</span> (flags &amp; (ENCRYPTED | CONTINUED)) <span class="keywordflow">throw</span> HeaderErr();00057         <span class="keywordflow">if</span> (m_inQueue.<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz7_11">Skip</a>(6)!=6) <span class="keywordflow">throw</span> HeaderErr();    <span class="comment">// Skip file time, extra flags and OS type</span>00058 00059         <span class="keywordflow">if</span> (flags &amp; EXTRA_FIELDS)       <span class="comment">// skip extra fields</span>00060         {00061                 word16 length;00062                 <span class="keywordflow">if</span> (m_inQueue.<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz7_6">GetWord16</a>(length, LITTLE_ENDIAN_ORDER) != 2) <span class="keywordflow">throw</span> HeaderErr();00063                 <span class="keywordflow">if</span> (m_inQueue.<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz7_11">Skip</a>(length)!=length) <span class="keywordflow">throw</span> HeaderErr();00064         }00065 00066         <span class="keywordflow">if</span> (flags &amp; FILENAME)   <span class="comment">// skip filename</span>00067                 <span class="keywordflow">do</span>00068                         <span class="keywordflow">if</span>(!m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera8">Get</a>(b)) <span class="keywordflow">throw</span> HeaderErr();00069                 <span class="keywordflow">while</span> (b);00070 00071         <span class="keywordflow">if</span> (flags &amp; COMMENTS)   <span class="comment">// skip comments</span>00072                 <span class="keywordflow">do</span>00073                         <span class="keywordflow">if</span>(!m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera8">Get</a>(b)) <span class="keywordflow">throw</span> HeaderErr();00074                 <span class="keywordflow">while</span> (b);00075 }00076 00077 <span class="keywordtype">void</span> Gunzip::ProcessDecompressedData(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00078 {00079         <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(inString, length);00080         m_crc.<a class="code" href="class_c_r_c32.html#_c_r_c32a1">Update</a>(inString, length);00081         m_length += length;00082 }00083 00084 <span class="keywordtype">void</span> Gunzip::ProcessPoststreamTail()00085 {00086         <a class="code" href="class_sec_block.html">SecByteBlock</a> crc(4);00087         <span class="keywordflow">if</span> (m_inQueue.<a class="code" href="class_byte_queue.html#_d_e_r_set_encodera8">Get</a>(crc, 4) != 4)00088                 <span class="keywordflow">throw</span> TailErr();00089         <span class="keywordflow">if</span> (!m_crc.<a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea15">Verify</a>(crc))00090                 <span class="keywordflow">throw</span> CrcErr();00091 00092         word32 lengthCheck;00093         <span class="keywordflow">if</span> (m_inQueue.<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz7_7">GetWord32</a>(lengthCheck, LITTLE_ENDIAN_ORDER) != 4)00094                 <span class="keywordflow">throw</span> TailErr();00095         <span class="keywordflow">if</span> (lengthCheck != m_length)00096                 <span class="keywordflow">throw</span> LengthErr();00097 }00098 00099 NAMESPACE_END</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:16 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 + -