mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-12 17:38:32 +02:00
Fix obscure Windows line ending issue with decode
See https://bugs.python.org/issue40863
This commit is contained in:
parent
fd6bdd79fb
commit
ce4df8ee23
4 changed files with 6 additions and 10 deletions
|
@ -157,7 +157,7 @@ class Journal:
|
|||
return f.read()
|
||||
|
||||
def _store(self, filename, text):
|
||||
with open(filename, "w", encoding="utf-8") as f:
|
||||
with open(filename, "wb") as f:
|
||||
f.write(text)
|
||||
|
||||
def _parse(self, journal_txt):
|
||||
|
|
|
@ -30,7 +30,7 @@ class BasePasswordEncryption(BaseEncryption):
|
|||
def password(self, value: str) -> None:
|
||||
self._password = value
|
||||
|
||||
def encrypt(self, text: str) -> str:
|
||||
def encrypt(self, text: str) -> bytes:
|
||||
if not self.password:
|
||||
self.password = create_password(self._journal_name)
|
||||
return self._encrypt(text)
|
||||
|
|
|
@ -40,12 +40,8 @@ class Jrnlv2Encryption(BasePasswordEncryption):
|
|||
key = kdf.derive(password)
|
||||
self._key = base64.urlsafe_b64encode(key)
|
||||
|
||||
def _encrypt(self, text: str) -> str:
|
||||
return (
|
||||
Fernet(self._key)
|
||||
.encrypt(text.encode(self._encoding))
|
||||
.decode(self._encoding)
|
||||
)
|
||||
def _encrypt(self, text: str) -> bytes:
|
||||
return Fernet(self._key).encrypt(text.encode(self._encoding))
|
||||
|
||||
def _decrypt(self, text: bytes) -> str | None:
|
||||
try:
|
||||
|
|
|
@ -7,8 +7,8 @@ class NoEncryption(BaseEncryption):
|
|||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def _encrypt(self, text: str) -> str:
|
||||
return text
|
||||
def _encrypt(self, text: str) -> bytes:
|
||||
return text.encode(self._encoding)
|
||||
|
||||
def _decrypt(self, text: bytes) -> str:
|
||||
return text.decode(self._encoding)
|
||||
|
|
Loading…
Add table
Reference in a new issue