From 34142a6c10fced8810385948174cbf48ce7117a4 Mon Sep 17 00:00:00 2001 From: m-holger Date: Fri, 4 Jul 2025 14:51:53 +0100 Subject: [PATCH] Refactor `QPDF::isEncrypted` methods to simplify logic, reduce redundancy, and directly access encryption parameters for improved clarity and maintainability. --- libqpdf/QPDF_encryption.cc | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index 15690ca..0d6c9d4 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -1236,9 +1236,12 @@ QPDF::isEncrypted() const bool QPDF::isEncrypted(int& R, int& P) { - int V; - encryption_method_e stream, string, file; - return isEncrypted(R, P, V, stream, string, file); + if (!m->encp->encrypted) { + return false; + } + P = m->encp->encryption_P; + R = m->encp->encryption_R; + return true; } bool @@ -1250,22 +1253,16 @@ QPDF::isEncrypted( encryption_method_e& string_method, encryption_method_e& file_method) { - if (m->encp->encrypted) { - QPDFObjectHandle trailer = getTrailer(); - QPDFObjectHandle encrypt = trailer.getKey("/Encrypt"); - QPDFObjectHandle Pkey = encrypt.getKey("/P"); - QPDFObjectHandle Rkey = encrypt.getKey("/R"); - QPDFObjectHandle Vkey = encrypt.getKey("/V"); - P = static_cast(Pkey.getIntValue()); - R = Rkey.getIntValueAsInt(); - V = Vkey.getIntValueAsInt(); - stream_method = m->encp->cf_stream; - string_method = m->encp->cf_string; - file_method = m->encp->cf_file; - return true; - } else { + if (!m->encp->encrypted) { return false; } + P = m->encp->encryption_P; + R = m->encp->encryption_R; + V = m->encp->encryption_V; + stream_method = m->encp->cf_stream; + string_method = m->encp->cf_string; + file_method = m->encp->cf_file; + return true; } bool -- libgit2 0.21.4