Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 23e07fd43e778a61ff4b78161a3e2389 > files > 2456

cryptopp-doc-5.6.1-5.fc14.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Crypto++: zlib.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.4 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Crypto++</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">zlib.cpp</div>  </div>
</div>
<div class="contents">
<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">// &quot;zlib&quot; 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 &quot;pch.h&quot;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &quot;zlib.h&quot;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &quot;zdeflate.h&quot;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &quot;zinflate.h&quot;</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>00020 <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;<a class="code" href="class_buffered_transformation.html#a92c60616792d7bce5cd41eaffbd1c3cc" title="input a 16-bit word">PutWord16</a>(RoundUpToMultipleOf(cmf*256+flags, 31));
<a name="l00026"></a>00026 }
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="keywordtype">void</span> ZlibCompressor::ProcessUncompressedData(<span class="keyword">const</span> byte *inString, <span class="keywordtype">size_t</span> length)
<a name="l00029"></a>00029 {
<a name="l00030"></a>00030         m_adler32.<a class="code" href="class_adler32.html#a84c3d47f039beab76b5f902ff558ac49" title="process more input">Update</a>(inString, length);
<a name="l00031"></a>00031 }
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <span class="keywordtype">void</span> ZlibCompressor::WritePoststreamTail()
<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         m_adler32.<a class="code" href="class_hash_transformation.html#aa0b8c7a110d8968268fd02ec32b9a8e8" 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#ac8fc888888b2dad88bf64fc703044a93" 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#ae70658b0d271f8e114ac6c3cc9774ede" title="input a byte for processing">Put</a>(adler32, 4);
<a name="l00038"></a>00038 }
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ZlibCompressor::GetCompressionLevel()<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[GetDeflateLevel()];
<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#a2811c881df0f9cd29a8a047c12c3a744">00048</a> <a class="code" href="class_zlib_decompressor.html#a2811c881df0f9cd29a8a047c12c3a744">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#a92752eebac10497211d7a065faba8725" 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> (!m_inQueue.<a class="code" href="class_byte_queue.html#a19413e3aa72b749e3771d617e8eca632" title="try to retrieve a single byte">Get</a>(cmf) || !m_inQueue.<a class="code" href="class_byte_queue.html#a19413e3aa72b749e3771d617e8eca632" 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&#39;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#ac8fc888888b2dad88bf64fc703044a93" 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#ae70658b0d271f8e114ac6c3cc9774ede" title="input a byte for processing">Put</a>(inString, length);
<a name="l00078"></a>00078         m_adler32.<a class="code" href="class_adler32.html#a84c3d47f039beab76b5f902ff558ac49" 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> (m_inQueue.<a class="code" href="class_byte_queue.html#a19413e3aa72b749e3771d617e8eca632" 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#a16c4aecd047015d513feef4ed5b929ba" title="verify that digest is a valid digest for the current message, then reinitialize the object...">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></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Sun Oct 16 2011 for Crypto++ by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>