Skip to content

Commit

Permalink
🥅 add exceptino catch on file read fro decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
Jezza34000 committed Jan 21, 2025
1 parent 430b9dc commit 2620bfa
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pypetkitapi/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,22 @@ async def _decrypt_file(file_path: Path, aes_key: str) -> bytes | None:
iv: bytes = b"\x61" * 16
cipher: Any = AES.new(key_bytes, AES.MODE_CBC, iv)

async with aio_open(file_path, "rb") as encrypted_file:
encrypted_data: bytes = await encrypted_file.read()
try:
async with aio_open(file_path, "rb") as encrypted_file:
encrypted_data: bytes = await encrypted_file.read()
return encrypted_data
except FileNotFoundError:
_LOGGER.debug("Error: The file '%s' was not found.", file_path)
except PermissionError:
_LOGGER.error(
"Error: Insufficient permissions to access the file '%s'.", file_path
)
except OSError as e:
_LOGGER.error(
"System error while accessing the file '%s': %s", file_path, e
)
except Exception as e: # noqa: BLE001
_LOGGER.error("An unexpected error occurred: %s", e)

decrypted_data: bytes = cipher.decrypt(encrypted_data)

Expand Down

0 comments on commit 2620bfa

Please sign in to comment.