Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since this pull request is getting quite large already, I am leaving the work of implementing more sanity checks in terms of what is possible depending on the version/revision, actual test cases and an
EncryptionStateBuilder
when creating new PDF documents for the next pull request, but I think those are the tasks that are currently left to do.This pull request implements
Document::encrypt()
.The
EncryptionState
has been reworked to store all the relevant pieces of information from the encrypted dictionary, that way we can encode it back to an encrypted dictionary when encrypting it. The decoding logic has also been moved intoEncryptionState::decode()
. In addition, some fixes were required to make this work such as storing the default stream/string crypt filters by name and addingCryptFilter::method()
which returns the name to be stored in the CFM field.This pull request also implements the remaining algorithms to compute the owner values, user values and permissions for revision 6 as well as the algorithm to verify the permissions. Part of which will become relevant for the
EncryptionStateBuilder
.Most of the other commits clean up the code a bit here and there.
Document::encrypt()
usesEncryptionState::encode()
to create the encrypted dictionary and store it in the trailer of the documents and proceeds to useencrypt_object()
to encrypts the stream/string objects.