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

ENH: Add AES support for encrypting PDF files (merged via other PRs) #1816

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a1c5542
ENH: implements encrypt parts for class Encryption
exiledkingcc Apr 26, 2023
6bff24a
ENH: use class Encryption for PdfWriter to encrypt
exiledkingcc Apr 27, 2023
62699bf
ENH: support AES for encrypting
exiledkingcc Apr 27, 2023
7a60a9d
ROB: fix when PdfWriter encrypt multiple times
exiledkingcc Apr 27, 2023
22c9a4b
ROB: fix test_workflows.py::test_basic_features
exiledkingcc Apr 27, 2023
a915020
STY: cleanup. remove deprecated `writeToStream`
exiledkingcc Apr 27, 2023
37846e7
STY: cleanup
exiledkingcc Apr 27, 2023
b903684
ROB: fix test_page.test_empyt_password_1088
exiledkingcc Apr 27, 2023
7e60138
TST: fix tests when no PyCryptodome installed
exiledkingcc Apr 28, 2023
0658468
MAINT: remove useless _security.py
exiledkingcc Apr 29, 2023
8d8d01f
ROB: fix calling `PdfWriter::encrypt` multiple times
exiledkingcc Apr 29, 2023
e49abc5
Merge branch 'main' into encrypt
MartinThoma Apr 30, 2023
ab572ef
Merge branch 'main' into encrypt
MartinThoma Apr 30, 2023
5385eaf
Merge branch 'main' into encrypt
MartinThoma Apr 30, 2023
4ad18be
Apply black
MartinThoma Apr 30, 2023
6731e49
Merge branch 'main' into encrypt
MartinThoma Apr 30, 2023
c23afca
STY
MartinThoma Apr 30, 2023
bf429fa
STY
MartinThoma Apr 30, 2023
498305d
STY
MartinThoma Apr 30, 2023
53c5414
STY
MartinThoma Apr 30, 2023
34dacd4
Merge branch 'main' into encrypt
MartinThoma Apr 30, 2023
2a2f5e4
ROB: make PdfWriter::encrypt compatible
exiledkingcc May 2, 2023
5d88173
TST: increase code coverage
exiledkingcc May 8, 2023
c0d7098
Merge branch 'main' into encrypt
MartinThoma May 20, 2023
165f31c
Merge branch 'main' into encrypt
MartinThoma Jun 11, 2023
864112a
Merge branch 'main' into encrypt
exiledkingcc Jun 16, 2023
31d5225
Merge branch 'main' into encrypt
MartinThoma Jun 21, 2023
712acb2
Merge branch 'main' into encrypt
MartinThoma Jun 25, 2023
0bb6b27
Merge branch 'main' into encrypt
MartinThoma Jun 25, 2023
c133384
Merge branch 'main' into encrypt
MartinThoma Jun 25, 2023
6232dbc
Merge branch 'main' into encrypt
MartinThoma Jul 2, 2023
43f636c
Merge branch 'main' into encrypt
MartinThoma Jul 2, 2023
ac82785
Merge branch 'main' into encrypt
MartinThoma Jul 2, 2023
a7cfdb4
Merge branch 'main' into encrypt
MartinThoma Jul 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions pypdf/_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,11 +941,11 @@ class Encryption:

def __init__(
self,
*,
V: int,
R: int,
Length: int,
P: int,
entry: DictionaryObject,
EncryptMetadata: bool,
first_id_entry: bytes,
StmF: str,
Expand All @@ -957,7 +957,7 @@ def __init__(
# use same name as keys of encryption dictionaries entries
self.V = V
self.R = R
self.Length = Length # key_size
self.Length = Length
self.P = (P + 0x100000000) % 0x100000000 # maybe P < 0
self.EncryptMetadata = EncryptMetadata
self.id1_entry = first_id_entry
Expand Down Expand Up @@ -1216,11 +1216,9 @@ def compute_values_v4(self, user_password: bytes, owner_password: bytes) -> None

@staticmethod
def read(encryption_entry: DictionaryObject, first_id_entry: bytes) -> "Encryption":
filter = encryption_entry.get("/Filter")
if filter != "/Standard":
raise NotImplementedError(
"only Standard PDF encryption handler is available"
)
Filter = encryption_entry.get("/Filter")
if Filter != "/Standard":
raise NotImplementedError("only Standard PDF encryption handler is available")
if "/SubFilter" in encryption_entry:
raise NotImplementedError("/SubFilter NOT supported")

Expand Down
4 changes: 1 addition & 3 deletions pypdf/_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def get_object(self) -> Optional["PdfObjectProtocol"]:
def hash_value(self) -> bytes:
...

def write_to_stream(
self, stream: StreamType, encryption_key: Union[None, str, bytes] = None
) -> None:
def write_to_stream(self, stream: StreamType) -> None:
...


Expand Down
4 changes: 1 addition & 3 deletions pypdf/generic/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ def getObject(self) -> Optional["PdfObject"]: # deprecated
deprecation_with_replacement("getObject", "get_object", "3.0.0")
return self.get_object()

def write_to_stream(
self, stream: StreamType, encryption_key: Union[None, str, bytes] = None
) -> None:
def write_to_stream(self, stream: StreamType) -> None:
raise NotImplementedError


Expand Down
2 changes: 1 addition & 1 deletion pypdf/generic/_outline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Union
from typing import Any

from .._utils import StreamType, deprecate_no_replacement, deprecation_with_replacement
from ._base import NameObject
Expand Down
1 change: 0 additions & 1 deletion pypdf/xmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
List,
Optional,
TypeVar,
Union,
cast,
)
from xml.dom.minidom import Document, parseString
Expand Down