diff options
author | Jay Berkenbilt <jberkenbilt@users.noreply.github.com> | 2023-12-16 17:31:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-16 17:31:11 +0100 |
commit | b0b6d9f21fe77fb7b46469529bf252f0dbcaa551 (patch) | |
tree | 612562863dbf4364e41e2086b701b92761c18e72 /libqpdf/QPDF_encryption.cc | |
parent | d7a364b882be44c93dc4a843bcca2ae63e805c2c (diff) | |
parent | 368666899fe24885fbe05ea03688fa985645ebd9 (diff) | |
download | qpdf-b0b6d9f21fe77fb7b46469529bf252f0dbcaa551.tar.zst |
Merge pull request #1067 from m-holger/pl_buff
Reduce copying of Buffer contents
Diffstat (limited to 'libqpdf/QPDF_encryption.cc')
-rw-r--r-- | libqpdf/QPDF_encryption.cc | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index b5cc44ee..1dd7b963 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -229,13 +229,11 @@ process_with_aes( aes.writeString(data); } aes.finish(); - auto bufp = buffer.getBufferSharedPointer(); if (outlength == 0) { - outlength = bufp->getSize(); + return buffer.getString(); } else { - outlength = std::min(outlength, bufp->getSize()); + return buffer.getString().substr(0, outlength); } - return {reinterpret_cast<char*>(bufp->getBuffer()), outlength}; } static std::string @@ -1021,8 +1019,7 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) key.length()); pl.writeString(str); pl.finish(); - auto buf = bufpl.getBufferSharedPointer(); - str = std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize()); + str = bufpl.getString(); } else { QTC::TC("qpdf", "QPDF_encryption rc4 decode string"); size_t vlen = str.length(); @@ -1041,6 +1038,9 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) } } +// Prepend a decryption pipeline to 'pipeline'. The decryption pipeline (returned as +// 'decrypt_pipeline' must be owned by the caller to ensure that it stays alive while the pipeline +// is in use. void QPDF::decryptStream( std::shared_ptr<EncryptionParameters> encp, @@ -1049,7 +1049,7 @@ QPDF::decryptStream( Pipeline*& pipeline, QPDFObjGen const& og, QPDFObjectHandle& stream_dict, - std::vector<std::shared_ptr<Pipeline>>& heap) + std::unique_ptr<Pipeline>& decrypt_pipeline) { std::string type; if (stream_dict.getKey("/Type").isName()) { @@ -1085,8 +1085,7 @@ QPDF::decryptStream( crypt_params.getKey("/Name").isName()) { QTC::TC("qpdf", "QPDF_encrypt crypt array"); method = interpretCF(encp, crypt_params.getKey("/Name")); - method_source = "stream's Crypt " - "decode parameters (array)"; + method_source = "stream's Crypt decode parameters (array)"; } } } @@ -1135,10 +1134,9 @@ QPDF::decryptStream( } } 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"); - new_pipeline = std::make_shared<Pl_AES_PDF>( + decrypt_pipeline = std::make_unique<Pl_AES_PDF>( "AES stream decryption", pipeline, false, @@ -1146,14 +1144,13 @@ QPDF::decryptStream( key.length()); } else { QTC::TC("qpdf", "QPDF_encryption rc4 decode stream"); - new_pipeline = std::make_shared<Pl_RC4>( + decrypt_pipeline = std::make_unique<Pl_RC4>( "RC4 stream decryption", pipeline, QUtil::unsigned_char_pointer(key), toI(key.length())); } - pipeline = new_pipeline.get(); - heap.push_back(new_pipeline); + pipeline = decrypt_pipeline.get(); } void |