From fafd50bb20d98e48729957fd16008768a7d2af46 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 2 Nov 2025 11:26:34 +0000 Subject: [PATCH] Refactor `Pl_MD5`: move implementation to `MD5.cc`, update `CMakeLists.txt`, and clean up unused file. --- libqpdf/CMakeLists.txt | 1 - libqpdf/MD5.cc | 28 ++++++++++++++++++++++++++++ libqpdf/Pl_MD5.cc | 29 ----------------------------- 3 files changed, 28 insertions(+), 30 deletions(-) delete mode 100644 libqpdf/Pl_MD5.cc diff --git a/libqpdf/CMakeLists.txt b/libqpdf/CMakeLists.txt index 1f1580b..3e5a703 100644 --- a/libqpdf/CMakeLists.txt +++ b/libqpdf/CMakeLists.txt @@ -44,7 +44,6 @@ set(libqpdf_SOURCES Pl_Flate.cc Pl_Function.cc Pl_LZWDecoder.cc - Pl_MD5.cc Pl_OStream.cc Pl_PNGFilter.cc Pl_QPDFTokenizer.cc diff --git a/libqpdf/MD5.cc b/libqpdf/MD5.cc index ed59650..b28cdc0 100644 --- a/libqpdf/MD5.cc +++ b/libqpdf/MD5.cc @@ -1,5 +1,7 @@ #include +#include + #include #include #include @@ -163,3 +165,29 @@ MD5::checkFileChecksum(char const* const checksum, char const* filename, qpdf_of } return result; } + +void +Pl_MD5::write(unsigned char const* buf, size_t len) +{ + if (enabled) { + if (!in_progress) { + md5.reset(); + in_progress = true; + } + + // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits. + static size_t const max_bytes = 1 << 30; + size_t bytes_left = len; + unsigned char const* data = buf; + while (bytes_left > 0) { + size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); + md5.encodeDataIncrementally(reinterpret_cast(data), bytes); + bytes_left -= bytes; + data += bytes; + } + } + + if (next()) { + next()->write(buf, len); + } +} diff --git a/libqpdf/Pl_MD5.cc b/libqpdf/Pl_MD5.cc deleted file mode 100644 index 5cf5dba..0000000 --- a/libqpdf/Pl_MD5.cc +++ /dev/null @@ -1,29 +0,0 @@ -#include - -#include - -void -Pl_MD5::write(unsigned char const* buf, size_t len) -{ - if (enabled) { - if (!in_progress) { - md5.reset(); - in_progress = true; - } - - // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits. - static size_t const max_bytes = 1 << 30; - size_t bytes_left = len; - unsigned char const* data = buf; - while (bytes_left > 0) { - size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); - md5.encodeDataIncrementally(reinterpret_cast(data), bytes); - bytes_left -= bytes; - data += bytes; - } - } - - if (next()) { - next()->write(buf, len); - } -} -- libgit2 0.21.4