diff options
author | Jay Berkenbilt <jberkenbilt@users.noreply.github.com> | 2022-07-24 20:41:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-24 20:41:33 +0200 |
commit | 5696a507b6dacf34d066810a3f2fca3525eb02f5 (patch) | |
tree | b0009760e0f76c28aa99581e4bc6087adf93749f /libqpdf/QPDF_encryption.cc | |
parent | 6f1041afb8e6d1f57169cd4c79f42a7c1ce94da8 (diff) | |
parent | 8b4afa428e9caa1a34cad434dfe8a3e01e5a24d3 (diff) | |
download | qpdf-5696a507b6dacf34d066810a3f2fca3525eb02f5.tar.zst |
Merge pull request #731 from m-holger/og_unparse
Tidy QPDFObjGen related code
Diffstat (limited to 'libqpdf/QPDF_encryption.cc')
-rw-r--r-- | libqpdf/QPDF_encryption.cc | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index 5a7968ca..8c35b992 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -1075,8 +1075,7 @@ QPDF::initializeEncryption() std::string QPDF::getKeyForObject( std::shared_ptr<EncryptionParameters> encp, - int objid, - int generation, + QPDFObjGen const& og, bool use_aes) { if (!encp->encrypted) { @@ -1084,26 +1083,24 @@ QPDF::getKeyForObject( "request for encryption key in non-encrypted PDF"); } - if (!((objid == encp->cached_key_objid) && - (generation == encp->cached_key_generation))) { + if (og != encp->cached_key_og) { encp->cached_object_encryption_key = compute_data_key( encp->encryption_key, - objid, - generation, + og.getObj(), + og.getGen(), use_aes, encp->encryption_V, encp->encryption_R); - encp->cached_key_objid = objid; - encp->cached_key_generation = generation; + encp->cached_key_og = og; } return encp->cached_object_encryption_key; } void -QPDF::decryptString(std::string& str, int objid, int generation) +QPDF::decryptString(std::string& str, QPDFObjGen const& og) { - if (objid == 0) { + if (!og.isIndirect()) { return; } bool use_aes = false; @@ -1139,8 +1136,7 @@ QPDF::decryptString(std::string& str, int objid, int generation) } } - std::string key = - getKeyForObject(this->m->encp, objid, generation, use_aes); + std::string key = getKeyForObject(this->m->encp, og, use_aes); try { if (use_aes) { QTC::TC("qpdf", "QPDF_encryption aes decode string"); @@ -1175,9 +1171,8 @@ QPDF::decryptString(std::string& str, int objid, int generation) this->m->file->getName(), this->m->last_object_description, this->m->file->getLastOffset(), - "error decrypting string for object " + - QUtil::int_to_string(objid) + " " + - QUtil::int_to_string(generation) + ": " + e.what()); + "error decrypting string for object " + og.unparse() + ": " + + e.what()); } } @@ -1187,8 +1182,7 @@ QPDF::decryptStream( std::shared_ptr<InputSource> file, QPDF& qpdf_for_warning, Pipeline*& pipeline, - int objid, - int generation, + QPDFObjGen const& og, QPDFObjectHandle& stream_dict, std::vector<std::shared_ptr<Pipeline>>& heap) { @@ -1283,7 +1277,7 @@ QPDF::decryptStream( break; } } - std::string key = getKeyForObject(encp, objid, generation, use_aes); + std::string key = getKeyForObject(encp, og, use_aes); std::shared_ptr<Pipeline> new_pipeline; if (use_aes) { QTC::TC("qpdf", "QPDF_encryption aes decode stream"); |