Skip to content

Commit

Permalink
MAINT: Remove private _security submodule
Browse files Browse the repository at this point in the history
This PR was made to avoid breaking changes the original PR introduced.
We want to remove the outdated parameters, but not at the moment.
See https://pypdf.readthedocs.io/en/latest/dev/deprecations.html

Full credit for the work goes to exiledkingcc via PR #1816

Co-authored-by: exiledkingcc <exiledkingcc@gmail.com>
  • Loading branch information
MartinThoma and exiledkingcc committed Jul 2, 2023
1 parent 71be38b commit 0a260b9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 379 deletions.
314 changes: 0 additions & 314 deletions pypdf/_security.py

This file was deleted.

36 changes: 12 additions & 24 deletions pypdf/generic/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,8 @@ def original_bytes(self) -> bytes:
def write_to_stream(
self, stream: StreamType, encryption_key: Union[None, str, bytes] = None
) -> None:
bytearr = self
if encryption_key:
from .._security import RC4_encrypt

bytearr = RC4_encrypt(encryption_key, bytearr) # type: ignore
stream.write(b"<")
stream.write(binascii.hexlify(bytearr))
stream.write(binascii.hexlify(self))
stream.write(b">")

def writeToStream(
Expand Down Expand Up @@ -571,24 +566,17 @@ def write_to_stream(
self, stream: StreamType, encryption_key: Union[None, str, bytes] = None
) -> None:
bytearr = self.get_encoded_bytes()
if encryption_key:
from .._security import RC4_encrypt

bytearr = RC4_encrypt(encryption_key, bytearr)
obj = ByteStringObject(bytearr)
obj.write_to_stream(stream)
else:
stream.write(b"(")
for c in bytearr:
if not chr(c).isalnum() and c != b" ":
# This:
# stream.write(b_(rf"\{c:0>3o}"))
# gives
# https://github.com/davidhalter/parso/issues/207
stream.write(b_("\\%03o" % c))
else:
stream.write(b_(chr(c)))
stream.write(b")")
stream.write(b"(")
for c in bytearr:
if not chr(c).isalnum() and c != b" ":
# This:
# stream.write(b_(rf"\{c:0>3o}"))
# gives
# https://github.com/davidhalter/parso/issues/207
stream.write(b_("\\%03o" % c))
else:
stream.write(b_(chr(c)))
stream.write(b")")

def writeToStream(
self, stream: StreamType, encryption_key: Union[None, str, bytes]
Expand Down
7 changes: 1 addition & 6 deletions pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,7 @@ def write_to_stream(
DictionaryObject.write_to_stream(self, stream, encryption_key)
del self[SA.LENGTH]
stream.write(b"\nstream\n")
data = self._data
if encryption_key:
from .._security import RC4_encrypt

data = RC4_encrypt(encryption_key, data)
stream.write(data)
stream.write(self._data)
stream.write(b"\nendstream")

@staticmethod
Expand Down
Loading

0 comments on commit 0a260b9

Please sign in to comment.