Skip to content

Commit

Permalink
bluntly ignore calls to cryptography.hazmat
Browse files Browse the repository at this point in the history
  • Loading branch information
0xabu committed Sep 4, 2021
1 parent 96b2043 commit 624fc92
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
4 changes: 3 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ disallow_incomplete_defs = True
disallow_untyped_decorators = True
no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
warn_return_any = True
no_implicit_reexport = True
strict_equality = True

# This seems impossible to leave on in a version-independent manner
warn_unused_ignores = False

[mypy-pdfminer.*]
disallow_untyped_defs = True

Expand Down
20 changes: 8 additions & 12 deletions pdfminer/pdfdocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,8 @@ def decrypt_aes128(self, objid: int, genno: int, data: bytes) -> bytes:
ciphertext = data[16:]
cipher = Cipher(algorithms.AES(key),
modes.CBC(initialization_vector),
backend=default_backend())
return ( # type: ignore[no-any-return]
cipher.decryptor().update(ciphertext))
backend=default_backend()) # type: ignore
return cipher.decryptor().update(ciphertext) # type: ignore


class PDFStandardSecurityHandlerV5(PDFStandardSecurityHandlerV4):
Expand Down Expand Up @@ -532,19 +531,17 @@ def authenticate(self, password: str) -> Optional[bytes]:
hash.update(self.u)
cipher = Cipher(algorithms.AES(hash.digest()),
modes.CBC(b'\0' * 16),
backend=default_backend())
return ( # type: ignore[no-any-return]
cipher.decryptor().update(self.oe))
backend=default_backend()) # type: ignore
return cipher.decryptor().update(self.oe) # type: ignore
hash = sha256(password_bytes)
hash.update(self.u_validation_salt)
if hash.digest() == self.u_hash:
hash = sha256(password_bytes)
hash.update(self.u_key_salt)
cipher = Cipher(algorithms.AES(hash.digest()),
modes.CBC(b'\0' * 16),
backend=default_backend())
return ( # type: ignore[no-any-return]
cipher.decryptor().update(self.ue))
backend=default_backend()) # type: ignore
return cipher.decryptor().update(self.ue) # type: ignore
return None

def decrypt_aes256(self, objid: int, genno: int, data: bytes) -> bytes:
Expand All @@ -553,9 +550,8 @@ def decrypt_aes256(self, objid: int, genno: int, data: bytes) -> bytes:
assert self.key is not None
cipher = Cipher(algorithms.AES(self.key),
modes.CBC(initialization_vector),
backend=default_backend())
return ( # type: ignore[no-any-return]
cipher.decryptor().update(ciphertext))
backend=default_backend()) # type: ignore
return cipher.decryptor().update(ciphertext) # type: ignore


class PDFDocument:
Expand Down

0 comments on commit 624fc92

Please sign in to comment.