From c5efd0c35b21722d4003215adb9857ee923ebe01 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 6 Sep 2025 15:38:21 +0100 Subject: [PATCH] Refactor `QPDF_encryption`: replace `getKey` and `getName` with `Name` and operator[] for improved clarity and consistency, and remove unused test coverage entries. --- libqpdf/QPDF_encryption.cc | 21 ++++++++------------- qpdf/qpdf.testcov | 3 --- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index 33282a2..dde7cb2 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -676,8 +676,7 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf) throw qpdf.damagedPDF("/Encrypt in trailer dictionary is not a dictionary"); } - if (!(encryption_dict.getKey("/Filter").isName() && - (encryption_dict.getKey("/Filter").getName() == "/Standard"))) { + if (Name(encryption_dict["/Filter"]) != "/Standard") { throw unsupported("unsupported encryption filter"); } if (!encryption_dict.getKey("/SubFilter").null()) { @@ -765,16 +764,12 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf) for (auto const& [filter, cdict]: CF.as_dictionary()) { if (cdict.isDictionary()) { encryption_method_e method = e_none; - if (cdict.getKey("/CFM").isName()) { - std::string method_name = cdict.getKey("/CFM").getName(); - if (method_name == "/V2") { - QTC::TC("qpdf", "QPDF_encryption CFM V2"); + if (Name const& CFM = cdict["/CFM"]) { + if (CFM == "/V2") { method = e_rc4; - } else if (method_name == "/AESV2") { - QTC::TC("qpdf", "QPDF_encryption CFM AESV2"); + } else if (CFM == "/AESV2") { method = e_aes; - } else if (method_name == "/AESV3") { - QTC::TC("qpdf", "QPDF_encryption CFM AESV3"); + } else if (CFM == "/AESV3") { method = e_aesv3; } else { // Don't complain now -- maybe we won't need to reference this type. @@ -785,9 +780,9 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf) } } - cf_stream = interpretCF(encryption_dict.getKey("/StmF")); - cf_string = interpretCF(encryption_dict.getKey("/StrF")); - if (auto EFF = encryption_dict.getKey("/EFF"); EFF.isName()) { + cf_stream = interpretCF(encryption_dict["/StmF"]); + cf_string = interpretCF(encryption_dict["/StrF"]); + if (Name const& EFF = encryption_dict["/EFF"]) { // qpdf does not use this for anything other than informational purposes. This is // intended to instruct conforming writers on which crypt filter should be used when new // file attachments are added to a PDF file, but qpdf never generates encrypted files diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 5a51e84..2b46d76 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -143,8 +143,6 @@ qpdf-c called qpdf_init_write multiple times 0 QPDF_encryption rc4 decode string 0 QPDF_encryption rc4 decode stream 0 QPDFWriter not compressing metadata 0 -QPDF_encryption CFM V2 0 -QPDF_encryption CFM AESV2 0 QPDF_encryption aes decode string 0 QPDF_encryption cleartext metadata 0 QPDF_encryption aes decode stream 0 @@ -222,7 +220,6 @@ QPDFWriter remove ADBE 0 QPDFWriter remove existing Extensions 0 QPDFWriter preserve ADBE 0 QPDF_encryption skip 0x28 0 -QPDF_encryption CFM AESV3 0 qpdf-c called qpdf_get_pdf_extension_level 0 qpdf-c called qpdf_set_r5_encryption_parameters 0 qpdf-c called qpdf_set_r6_encryption_parameters 0 -- libgit2 0.21.4