mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-12 09:28:31 +02:00
clean up logging statements
This commit is contained in:
parent
dcdee69117
commit
45b05b9d34
5 changed files with 14 additions and 8 deletions
|
@ -12,17 +12,17 @@ from jrnl.messages import MsgText
|
||||||
|
|
||||||
class BaseEncryption(ABC):
|
class BaseEncryption(ABC):
|
||||||
def __init__(self, journal_name: str, config: dict):
|
def __init__(self, journal_name: str, config: dict):
|
||||||
logging.debug("BaseEncryption.__init__ start")
|
logging.debug("start")
|
||||||
self._encoding: str = "utf-8"
|
self._encoding: str = "utf-8"
|
||||||
self._journal_name: str = journal_name
|
self._journal_name: str = journal_name
|
||||||
self._config: dict = config
|
self._config: dict = config
|
||||||
|
|
||||||
def encrypt(self, text: str) -> bytes:
|
def encrypt(self, text: str) -> bytes:
|
||||||
logging.debug("BaseEncryption.encrypt start")
|
logging.debug("encrypting")
|
||||||
return self._encrypt(text)
|
return self._encrypt(text)
|
||||||
|
|
||||||
def decrypt(self, text: bytes) -> str:
|
def decrypt(self, text: bytes) -> str:
|
||||||
logging.debug("BaseEncryption.decrypt start")
|
logging.debug("decrypting")
|
||||||
if (result := self._decrypt(text)) is None:
|
if (result := self._decrypt(text)) is None:
|
||||||
raise JrnlException(
|
raise JrnlException(
|
||||||
Message(MsgText.DecryptionFailedGeneric, MsgStyle.ERROR)
|
Message(MsgText.DecryptionFailedGeneric, MsgStyle.ERROR)
|
||||||
|
|
|
@ -15,7 +15,7 @@ from jrnl.prompt import prompt_password
|
||||||
class BasePasswordEncryption(BaseEncryption):
|
class BasePasswordEncryption(BaseEncryption):
|
||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
logging.debug("BasePasswordEncryption.__init__ start")
|
logging.debug("start")
|
||||||
self._attempts: int = 0
|
self._attempts: int = 0
|
||||||
self._max_attempts: int = 3
|
self._max_attempts: int = 3
|
||||||
self._password: str = ""
|
self._password: str = ""
|
||||||
|
@ -34,12 +34,13 @@ class BasePasswordEncryption(BaseEncryption):
|
||||||
self._password = value
|
self._password = value
|
||||||
|
|
||||||
def encrypt(self, text: str) -> bytes:
|
def encrypt(self, text: str) -> bytes:
|
||||||
|
logging.debug("encrypting")
|
||||||
if not self.password:
|
if not self.password:
|
||||||
self.password = create_password(self._journal_name)
|
self.password = create_password(self._journal_name)
|
||||||
return self._encrypt(text)
|
return self._encrypt(text)
|
||||||
|
|
||||||
def decrypt(self, text: bytes) -> str:
|
def decrypt(self, text: bytes) -> str:
|
||||||
logging.debug("BasePasswordEncryption decrypt start")
|
logging.debug("decrypting")
|
||||||
if not self.password:
|
if not self.password:
|
||||||
self._prompt_password()
|
self._prompt_password()
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,13 @@ from jrnl.encryption.BasePasswordEncryption import BasePasswordEncryption
|
||||||
class Jrnlv1Encryption(BasePasswordEncryption):
|
class Jrnlv1Encryption(BasePasswordEncryption):
|
||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
logging.debug("Jrnlv1Encryption.__init__ start")
|
logging.debug("start")
|
||||||
|
|
||||||
def _encrypt(self, _: str) -> bytes:
|
def _encrypt(self, _: str) -> bytes:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def _decrypt(self, text: bytes) -> str | None:
|
def _decrypt(self, text: bytes) -> str | None:
|
||||||
|
logging.debug("decrypting")
|
||||||
iv, cipher = text[:16], text[16:]
|
iv, cipher = text[:16], text[16:]
|
||||||
password = self._password or ""
|
password = self._password or ""
|
||||||
decryption_key = hashlib.sha256(password.encode(self._encoding)).digest()
|
decryption_key = hashlib.sha256(password.encode(self._encoding)).digest()
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Jrnlv2Encryption(BasePasswordEncryption):
|
||||||
self._key: bytes = b""
|
self._key: bytes = b""
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
logging.debug("Jrnlv2Encryption.__init__ start")
|
logging.debug("start")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def password(self):
|
def password(self):
|
||||||
|
@ -43,9 +43,11 @@ class Jrnlv2Encryption(BasePasswordEncryption):
|
||||||
self._key = base64.urlsafe_b64encode(key)
|
self._key = base64.urlsafe_b64encode(key)
|
||||||
|
|
||||||
def _encrypt(self, text: str) -> bytes:
|
def _encrypt(self, text: str) -> bytes:
|
||||||
|
logging.debug("encrypting")
|
||||||
return Fernet(self._key).encrypt(text.encode(self._encoding))
|
return Fernet(self._key).encrypt(text.encode(self._encoding))
|
||||||
|
|
||||||
def _decrypt(self, text: bytes) -> str | None:
|
def _decrypt(self, text: bytes) -> str | None:
|
||||||
|
logging.debug("decrypting")
|
||||||
try:
|
try:
|
||||||
return Fernet(self._key).decrypt(text).decode(self._encoding)
|
return Fernet(self._key).decrypt(text).decode(self._encoding)
|
||||||
except (InvalidToken, IndexError):
|
except (InvalidToken, IndexError):
|
||||||
|
|
|
@ -7,11 +7,13 @@ from jrnl.encryption.BaseEncryption import BaseEncryption
|
||||||
|
|
||||||
class NoEncryption(BaseEncryption):
|
class NoEncryption(BaseEncryption):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
logging.debug("NoEncryption.__init__ start")
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
logging.debug("start")
|
||||||
|
|
||||||
def _encrypt(self, text: str) -> bytes:
|
def _encrypt(self, text: str) -> bytes:
|
||||||
|
logging.debug("encrypting")
|
||||||
return text.encode(self._encoding)
|
return text.encode(self._encoding)
|
||||||
|
|
||||||
def _decrypt(self, text: bytes) -> str:
|
def _decrypt(self, text: bytes) -> str:
|
||||||
|
logging.debug("decrypting")
|
||||||
return text.decode(self._encoding)
|
return text.decode(self._encoding)
|
||||||
|
|
Loading…
Add table
Reference in a new issue