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 44 Pl_Flate.cc
45 45 Pl_Function.cc
46 46 Pl_LZWDecoder.cc
47   - Pl_MD5.cc
48 47 Pl_OStream.cc
49 48 Pl_PNGFilter.cc
50 49 Pl_QPDFTokenizer.cc
... ...
libqpdf/MD5.cc
1 1 #include <qpdf/MD5.hh>
2 2  
  3 +#include <qpdf/Pl_MD5.hh>
  4 +
3 5 #include <qpdf/QIntC.hh>
4 6 #include <qpdf/QPDFCryptoProvider.hh>
5 7 #include <qpdf/QUtil.hh>
... ... @@ -163,3 +165,29 @@ MD5::checkFileChecksum(char const* const checksum, char const* filename, qpdf_of
163 165 }
164 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   -}