Commit fafd50bb20d98e48729957fd16008768a7d2af46

Authored by m-holger
1 parent 0ed62d9e

Refactor `Pl_MD5`: move implementation to `MD5.cc`, update `CMakeLists.txt`, and…

… clean up unused file.
libqpdf/CMakeLists.txt
@@ -44,7 +44,6 @@ set(libqpdf_SOURCES @@ -44,7 +44,6 @@ set(libqpdf_SOURCES
44 Pl_Flate.cc 44 Pl_Flate.cc
45 Pl_Function.cc 45 Pl_Function.cc
46 Pl_LZWDecoder.cc 46 Pl_LZWDecoder.cc
47 - Pl_MD5.cc  
48 Pl_OStream.cc 47 Pl_OStream.cc
49 Pl_PNGFilter.cc 48 Pl_PNGFilter.cc
50 Pl_QPDFTokenizer.cc 49 Pl_QPDFTokenizer.cc
libqpdf/MD5.cc
1 #include <qpdf/MD5.hh> 1 #include <qpdf/MD5.hh>
2 2
  3 +#include <qpdf/Pl_MD5.hh>
  4 +
3 #include <qpdf/QIntC.hh> 5 #include <qpdf/QIntC.hh>
4 #include <qpdf/QPDFCryptoProvider.hh> 6 #include <qpdf/QPDFCryptoProvider.hh>
5 #include <qpdf/QUtil.hh> 7 #include <qpdf/QUtil.hh>
@@ -163,3 +165,29 @@ MD5::checkFileChecksum(char const* const checksum, char const* filename, qpdf_of @@ -163,3 +165,29 @@ MD5::checkFileChecksum(char const* const checksum, char const* filename, qpdf_of
163 } 165 }
164 return result; 166 return result;
165 } 167 }
  168 +
  169 +void
  170 +Pl_MD5::write(unsigned char const* buf, size_t len)
  171 +{
  172 + if (enabled) {
  173 + if (!in_progress) {
  174 + md5.reset();
  175 + in_progress = true;
  176 + }
  177 +
  178 + // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits.
  179 + static size_t const max_bytes = 1 << 30;
  180 + size_t bytes_left = len;
  181 + unsigned char const* data = buf;
  182 + while (bytes_left > 0) {
  183 + size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
  184 + md5.encodeDataIncrementally(reinterpret_cast<char const*>(data), bytes);
  185 + bytes_left -= bytes;
  186 + data += bytes;
  187 + }
  188 + }
  189 +
  190 + if (next()) {
  191 + next()->write(buf, len);
  192 + }
  193 +}
libqpdf/Pl_MD5.cc deleted
1 -#include <qpdf/Pl_MD5.hh>  
2 -  
3 -#include <stdexcept>  
4 -  
5 -void  
6 -Pl_MD5::write(unsigned char const* buf, size_t len)  
7 -{  
8 - if (enabled) {  
9 - if (!in_progress) {  
10 - md5.reset();  
11 - in_progress = true;  
12 - }  
13 -  
14 - // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits.  
15 - static size_t const max_bytes = 1 << 30;  
16 - size_t bytes_left = len;  
17 - unsigned char const* data = buf;  
18 - while (bytes_left > 0) {  
19 - size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);  
20 - md5.encodeDataIncrementally(reinterpret_cast<char const*>(data), bytes);  
21 - bytes_left -= bytes;  
22 - data += bytes;  
23 - }  
24 - }  
25 -  
26 - if (next()) {  
27 - next()->write(buf, len);  
28 - }  
29 -}