diff --git a/jrnl/encryption/BaseEncryption.py b/jrnl/encryption/BaseEncryption.py index 538bee74..c69ddfb7 100644 --- a/jrnl/encryption/BaseEncryption.py +++ b/jrnl/encryption/BaseEncryption.py @@ -12,17 +12,17 @@ from jrnl.messages import MsgText class BaseEncryption(ABC): def __init__(self, journal_name: str, config: dict): - logging.debug("BaseEncryption.__init__ start") + logging.debug("start") self._encoding: str = "utf-8" self._journal_name: str = journal_name self._config: dict = config def encrypt(self, text: str) -> bytes: - logging.debug("BaseEncryption.encrypt start") + logging.debug("encrypting") return self._encrypt(text) def decrypt(self, text: bytes) -> str: - logging.debug("BaseEncryption.decrypt start") + logging.debug("decrypting") if (result := self._decrypt(text)) is None: raise JrnlException( Message(MsgText.DecryptionFailedGeneric, MsgStyle.ERROR) diff --git a/jrnl/encryption/BasePasswordEncryption.py b/jrnl/encryption/BasePasswordEncryption.py index 392c0575..4defdf53 100644 --- a/jrnl/encryption/BasePasswordEncryption.py +++ b/jrnl/encryption/BasePasswordEncryption.py @@ -15,7 +15,7 @@ from jrnl.prompt import prompt_password class BasePasswordEncryption(BaseEncryption): def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) - logging.debug("BasePasswordEncryption.__init__ start") + logging.debug("start") self._attempts: int = 0 self._max_attempts: int = 3 self._password: str = "" @@ -34,12 +34,13 @@ class BasePasswordEncryption(BaseEncryption): self._password = value def encrypt(self, text: str) -> bytes: + logging.debug("encrypting") if not self.password: self.password = create_password(self._journal_name) return self._encrypt(text) def decrypt(self, text: bytes) -> str: - logging.debug("BasePasswordEncryption decrypt start") + logging.debug("decrypting") if not self.password: self._prompt_password() diff --git a/jrnl/encryption/Jrnlv1Encryption.py b/jrnl/encryption/Jrnlv1Encryption.py index faeeda45..c6343380 100644 --- a/jrnl/encryption/Jrnlv1Encryption.py +++ b/jrnl/encryption/Jrnlv1Encryption.py @@ -15,12 +15,13 @@ from jrnl.encryption.BasePasswordEncryption import BasePasswordEncryption class Jrnlv1Encryption(BasePasswordEncryption): def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) - logging.debug("Jrnlv1Encryption.__init__ start") + logging.debug("start") def _encrypt(self, _: str) -> bytes: raise NotImplementedError def _decrypt(self, text: bytes) -> str | None: + logging.debug("decrypting") iv, cipher = text[:16], text[16:] password = self._password or "" decryption_key = hashlib.sha256(password.encode(self._encoding)).digest() diff --git a/jrnl/encryption/Jrnlv2Encryption.py b/jrnl/encryption/Jrnlv2Encryption.py index 6d9333df..aae10a37 100644 --- a/jrnl/encryption/Jrnlv2Encryption.py +++ b/jrnl/encryption/Jrnlv2Encryption.py @@ -19,7 +19,7 @@ class Jrnlv2Encryption(BasePasswordEncryption): self._key: bytes = b"" super().__init__(*args, **kwargs) - logging.debug("Jrnlv2Encryption.__init__ start") + logging.debug("start") @property def password(self): @@ -43,9 +43,11 @@ class Jrnlv2Encryption(BasePasswordEncryption): self._key = base64.urlsafe_b64encode(key) def _encrypt(self, text: str) -> bytes: + logging.debug("encrypting") return Fernet(self._key).encrypt(text.encode(self._encoding)) def _decrypt(self, text: bytes) -> str | None: + logging.debug("decrypting") try: return Fernet(self._key).decrypt(text).decode(self._encoding) except (InvalidToken, IndexError): diff --git a/jrnl/encryption/NoEncryption.py b/jrnl/encryption/NoEncryption.py index 5c0f4961..9196389c 100644 --- a/jrnl/encryption/NoEncryption.py +++ b/jrnl/encryption/NoEncryption.py @@ -7,11 +7,13 @@ from jrnl.encryption.BaseEncryption import BaseEncryption class NoEncryption(BaseEncryption): def __init__(self, *args, **kwargs): - logging.debug("NoEncryption.__init__ start") super().__init__(*args, **kwargs) + logging.debug("start") def _encrypt(self, text: str) -> bytes: + logging.debug("encrypting") return text.encode(self._encoding) def _decrypt(self, text: bytes) -> str: + logging.debug("decrypting") return text.decode(self._encoding)