mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-28 21:46:13 +02:00
Move all password handling to EncryptedJournal
This commit should greatly simplify all password handling logic. No passwords are stored in the config dict anymore. Only the Encrypted Journals have any password related logic. I also had to remove some password fields from the test files, which shows how dangerous the previous approach was. A slight code change could've leaked passwords to the config file. However, I had to change the install progress a little bit to make this work. It will now not ask you for a password right away but rather if you want to encrypt or not. Only if you reply 'y' will it ask you for the password later on.
This commit is contained in:
parent
c8d59727eb
commit
9664924096
15 changed files with 79 additions and 97 deletions
|
@ -41,6 +41,7 @@ class Journal:
|
|||
# Set up date parser
|
||||
self.search_tags = None # Store tags we're highlighting
|
||||
self.name = name
|
||||
self.entries = []
|
||||
|
||||
def __len__(self):
|
||||
"""Returns the number of entries"""
|
||||
|
@ -69,9 +70,9 @@ class Journal:
|
|||
filename = filename or self.config['journal']
|
||||
|
||||
if not os.path.exists(filename):
|
||||
self.create_file(filename)
|
||||
print(f"[Journal '{self.name}' created at {filename}]", file=sys.stderr)
|
||||
self._create(filename)
|
||||
|
||||
|
||||
text = self._load(filename)
|
||||
self.entries = self._parse(text)
|
||||
self.sort()
|
||||
|
@ -92,6 +93,11 @@ class Journal:
|
|||
return False
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def create_file(filename):
|
||||
with open(filename, "w"):
|
||||
pass
|
||||
|
||||
def _to_text(self):
|
||||
return "\n".join([str(e) for e in self.entries])
|
||||
|
||||
|
@ -101,10 +107,6 @@ class Journal:
|
|||
def _store(self, filename, text):
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
def _create(cls, filename):
|
||||
raise NotImplementedError
|
||||
|
||||
def _parse(self, journal_txt):
|
||||
"""Parses a journal that's stored in a string and returns a list of entries"""
|
||||
|
||||
|
@ -274,11 +276,6 @@ class Journal:
|
|||
|
||||
|
||||
class PlainJournal(Journal):
|
||||
@classmethod
|
||||
def _create(cls, filename):
|
||||
with open(filename, "a", encoding="utf-8"):
|
||||
pass
|
||||
|
||||
def _load(self, filename):
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
return f.read()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue