Commit 5806e30595b7f47d3a06c156b92a7cb034f84ba1
1 parent
f126bfa7
Refactor SF_Crypt to use `final` and improve `setDecodeParms`.
Updated `SF_Crypt` class methods and destructor to use the `final` specifier for clarity and stricter override rules. Refactored `setDecodeParms` logic for better readability and accurate handling of dictionary keys. Other minor adjustments contribute to code maintainability and correctness.
Showing
1 changed file
with
20 additions
and
16 deletions
libqpdf/QPDF_Stream.cc
| @@ -27,33 +27,37 @@ using namespace qpdf; | @@ -27,33 +27,37 @@ using namespace qpdf; | ||
| 27 | 27 | ||
| 28 | namespace | 28 | namespace |
| 29 | { | 29 | { |
| 30 | - class SF_Crypt: public QPDFStreamFilter | 30 | + class SF_Crypt final: public QPDFStreamFilter |
| 31 | { | 31 | { |
| 32 | public: | 32 | public: |
| 33 | SF_Crypt() = default; | 33 | SF_Crypt() = default; |
| 34 | - ~SF_Crypt() override = default; | 34 | + ~SF_Crypt() final = default; |
| 35 | 35 | ||
| 36 | bool | 36 | bool |
| 37 | - setDecodeParms(QPDFObjectHandle decode_parms) override | 37 | + setDecodeParms(QPDFObjectHandle decode_parms) final |
| 38 | { | 38 | { |
| 39 | - if (decode_parms.isNull()) { | ||
| 40 | - return true; | ||
| 41 | - } | ||
| 42 | - bool filterable = true; | ||
| 43 | - for (auto const& key: decode_parms.getKeys()) { | ||
| 44 | - if (((key == "/Type") || (key == "/Name")) && | ||
| 45 | - ((!decode_parms.hasKey("/Type")) || | ||
| 46 | - decode_parms.isDictionaryOfType("/CryptFilterDecodeParms"))) { | ||
| 47 | - // we handle this in decryptStream | ||
| 48 | - } else { | ||
| 49 | - filterable = false; | 39 | + // we only validate here - processing happens in decryptStream |
| 40 | + if (auto dict = decode_parms.as_dictionary(optional)) { | ||
| 41 | + for (auto const& [key, value]: dict) { | ||
| 42 | + if (key == "/Type" && | ||
| 43 | + (value.null() || | ||
| 44 | + (value.isName() && value.getName() == "/CryptFilterDecodeParms"))) { | ||
| 45 | + continue; | ||
| 46 | + } | ||
| 47 | + if (key == "/Name") { | ||
| 48 | + continue; | ||
| 49 | + } | ||
| 50 | + if (!value.null()) { | ||
| 51 | + return false; | ||
| 52 | + } | ||
| 50 | } | 53 | } |
| 54 | + return true; | ||
| 51 | } | 55 | } |
| 52 | - return filterable; | 56 | + return false; |
| 53 | } | 57 | } |
| 54 | 58 | ||
| 55 | Pipeline* | 59 | Pipeline* |
| 56 | - getDecodePipeline(Pipeline*) override | 60 | + getDecodePipeline(Pipeline*) final |
| 57 | { | 61 | { |
| 58 | // Not used -- handled by pipeStreamData | 62 | // Not used -- handled by pipeStreamData |
| 59 | return nullptr; | 63 | return nullptr; |