Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle the is_aes check without throwing errors #376

Merged
merged 2 commits into from
Feb 5, 2025

Conversation

StephanvanSchaik
Copy link
Contributor

Commit 9f22915 introduces a regression in 0.35 compared to 0.34 when decrypting a PDF document that does not use AES. Instead of decrypting the document, it throws an error that the CF dictionary is missing. Consequently, this prevents the document from being decrypted.

To remedy this, this pull request eliminates all uses of ? in the is_aes check to gracefully determine if the PDF document uses AES or not. It then proceeds to decrypt it accordingly.

Instead of using ?, we carefully convert all Result<T, E> types into Option<T> using .ok() in combination with .map() and .flatten() to walk through the series of dictionaries. Then at the final step we simply compare if the cfm is equal to b"AESV2". If any of the steps fails, we would get None, in which case we default to is_aes = false (rather than throwing an error).

Copy link

@genusistimelord genusistimelord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve these changes. @J-F-Liu I think this is acceptable and does indeed fix the encryption issue.

@J-F-Liu
Copy link
Owner

J-F-Liu commented Feb 5, 2025

Please use and_then to fix clippy warnings

@StephanvanSchaik
Copy link
Contributor Author

I just pushed a commit addressing the clippy lints.

@J-F-Liu J-F-Liu merged commit eaedf57 into J-F-Liu:main Feb 5, 2025
@StephanvanSchaik StephanvanSchaik deleted the aes-fix branch February 5, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants