Commit c5efd0c35b21722d4003215adb9857ee923ebe01

Authored by m-holger
1 parent 974bc7cf

Refactor `QPDF_encryption`: replace `getKey` and `getName` with `Name` and opera…

…tor[] for improved clarity and consistency, and remove unused test coverage entries.
libqpdf/QPDF_encryption.cc
@@ -676,8 +676,7 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf) @@ -676,8 +676,7 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf)
676 throw qpdf.damagedPDF("/Encrypt in trailer dictionary is not a dictionary"); 676 throw qpdf.damagedPDF("/Encrypt in trailer dictionary is not a dictionary");
677 } 677 }
678 678
679 - if (!(encryption_dict.getKey("/Filter").isName() &&  
680 - (encryption_dict.getKey("/Filter").getName() == "/Standard"))) { 679 + if (Name(encryption_dict["/Filter"]) != "/Standard") {
681 throw unsupported("unsupported encryption filter"); 680 throw unsupported("unsupported encryption filter");
682 } 681 }
683 if (!encryption_dict.getKey("/SubFilter").null()) { 682 if (!encryption_dict.getKey("/SubFilter").null()) {
@@ -765,16 +764,12 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf) @@ -765,16 +764,12 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf)
765 for (auto const& [filter, cdict]: CF.as_dictionary()) { 764 for (auto const& [filter, cdict]: CF.as_dictionary()) {
766 if (cdict.isDictionary()) { 765 if (cdict.isDictionary()) {
767 encryption_method_e method = e_none; 766 encryption_method_e method = e_none;
768 - if (cdict.getKey("/CFM").isName()) {  
769 - std::string method_name = cdict.getKey("/CFM").getName();  
770 - if (method_name == "/V2") {  
771 - QTC::TC("qpdf", "QPDF_encryption CFM V2"); 767 + if (Name const& CFM = cdict["/CFM"]) {
  768 + if (CFM == "/V2") {
772 method = e_rc4; 769 method = e_rc4;
773 - } else if (method_name == "/AESV2") {  
774 - QTC::TC("qpdf", "QPDF_encryption CFM AESV2"); 770 + } else if (CFM == "/AESV2") {
775 method = e_aes; 771 method = e_aes;
776 - } else if (method_name == "/AESV3") {  
777 - QTC::TC("qpdf", "QPDF_encryption CFM AESV3"); 772 + } else if (CFM == "/AESV3") {
778 method = e_aesv3; 773 method = e_aesv3;
779 } else { 774 } else {
780 // Don't complain now -- maybe we won't need to reference this type. 775 // Don't complain now -- maybe we won't need to reference this type.
@@ -785,9 +780,9 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf) @@ -785,9 +780,9 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf)
785 } 780 }
786 } 781 }
787 782
788 - cf_stream = interpretCF(encryption_dict.getKey("/StmF"));  
789 - cf_string = interpretCF(encryption_dict.getKey("/StrF"));  
790 - if (auto EFF = encryption_dict.getKey("/EFF"); EFF.isName()) { 783 + cf_stream = interpretCF(encryption_dict["/StmF"]);
  784 + cf_string = interpretCF(encryption_dict["/StrF"]);
  785 + if (Name const& EFF = encryption_dict["/EFF"]) {
791 // qpdf does not use this for anything other than informational purposes. This is 786 // qpdf does not use this for anything other than informational purposes. This is
792 // intended to instruct conforming writers on which crypt filter should be used when new 787 // intended to instruct conforming writers on which crypt filter should be used when new
793 // file attachments are added to a PDF file, but qpdf never generates encrypted files 788 // file attachments are added to a PDF file, but qpdf never generates encrypted files
qpdf/qpdf.testcov
@@ -143,8 +143,6 @@ qpdf-c called qpdf_init_write multiple times 0 @@ -143,8 +143,6 @@ qpdf-c called qpdf_init_write multiple times 0
143 QPDF_encryption rc4 decode string 0 143 QPDF_encryption rc4 decode string 0
144 QPDF_encryption rc4 decode stream 0 144 QPDF_encryption rc4 decode stream 0
145 QPDFWriter not compressing metadata 0 145 QPDFWriter not compressing metadata 0
146 -QPDF_encryption CFM V2 0  
147 -QPDF_encryption CFM AESV2 0  
148 QPDF_encryption aes decode string 0 146 QPDF_encryption aes decode string 0
149 QPDF_encryption cleartext metadata 0 147 QPDF_encryption cleartext metadata 0
150 QPDF_encryption aes decode stream 0 148 QPDF_encryption aes decode stream 0
@@ -222,7 +220,6 @@ QPDFWriter remove ADBE 0 @@ -222,7 +220,6 @@ QPDFWriter remove ADBE 0
222 QPDFWriter remove existing Extensions 0 220 QPDFWriter remove existing Extensions 0
223 QPDFWriter preserve ADBE 0 221 QPDFWriter preserve ADBE 0
224 QPDF_encryption skip 0x28 0 222 QPDF_encryption skip 0x28 0
225 -QPDF_encryption CFM AESV3 0  
226 qpdf-c called qpdf_get_pdf_extension_level 0 223 qpdf-c called qpdf_get_pdf_extension_level 0
227 qpdf-c called qpdf_set_r5_encryption_parameters 0 224 qpdf-c called qpdf_set_r5_encryption_parameters 0
228 qpdf-c called qpdf_set_r6_encryption_parameters 0 225 qpdf-c called qpdf_set_r6_encryption_parameters 0