mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-07 00:36:13 +02:00
Rework Encryption to enable future support of other encryption methods (#1602)
- initial pass through to rework encryption into separate module - little more cleanup - rename function, fix some linting issues - more cleaning - fix password bug in encryption - fix linting issue - more cleanup - move prompt into prompt.py - more cleanup - update the upgrade process for new encryption classes - general cleanup - turn into enum instead of strings - store status code so tests don't fail - standardize the load and store methods in journals - get rid of old PlainJournal class - typing cleanup - more cleanup - format - fix linting issue - Fix obscure Windows line ending issue with decode See https://bugs.python.org/issue40863 - fix for python 3.11 - add more typing - don't use class variables because that's not what we want - fix more type hints - jrnlv1 encryption doesn't support encryption anymore (it's deprecated) - keep logic for password attemps inside the class that uses it - take out old line of code - add some more logging - update logging statements - clean up logging statements - run linters - fix typo - Fix for new test from develop branch There was a new test added for re-encrypting a journal. This updates the refactor to match the old (previously untested) behavior of jrnl. Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
This commit is contained in:
parent
e6e08e5d3e
commit
fcc8d8e3fa
19 changed files with 437 additions and 267 deletions
|
@ -15,6 +15,7 @@ Also, please note that all (non-builtin) imports should be scoped to each functi
|
|||
avoid any possible overhead for these standalone commands.
|
||||
"""
|
||||
import argparse
|
||||
import logging
|
||||
import platform
|
||||
import sys
|
||||
|
||||
|
@ -24,7 +25,6 @@ from jrnl.messages import Message
|
|||
from jrnl.messages import MsgStyle
|
||||
from jrnl.messages import MsgText
|
||||
from jrnl.output import print_msg
|
||||
from jrnl.prompt import create_password
|
||||
|
||||
|
||||
def preconfig_diagnostic(_):
|
||||
|
@ -88,7 +88,6 @@ def postconfig_encrypt(
|
|||
Encrypt a journal in place, or optionally to a new file
|
||||
"""
|
||||
from jrnl.config import update_config
|
||||
from jrnl.EncryptedJournal import EncryptedJournal
|
||||
from jrnl.install import save_config
|
||||
from jrnl.Journal import open_journal
|
||||
|
||||
|
@ -107,21 +106,24 @@ def postconfig_encrypt(
|
|||
)
|
||||
)
|
||||
|
||||
new_journal = EncryptedJournal.from_journal(journal)
|
||||
|
||||
# If journal is encrypted, create new password
|
||||
if journal.config["encrypt"] is True:
|
||||
print(f"Journal {journal.name} is already encrypted. Create a new password.")
|
||||
new_journal.password = create_password(new_journal.name)
|
||||
logging.debug("Clearing encryption method...")
|
||||
|
||||
journal.config["encrypt"] = True
|
||||
new_journal.write(args.filename)
|
||||
if journal.config["encrypt"] is True:
|
||||
logging.debug("Journal already encrypted. Re-encrypting...")
|
||||
print(f"Journal {journal.name} is already encrypted. Create a new password.")
|
||||
journal.encryption_method.clear()
|
||||
else:
|
||||
journal.config["encrypt"] = True
|
||||
journal.encryption_method = None
|
||||
|
||||
journal.write(args.filename)
|
||||
|
||||
print_msg(
|
||||
Message(
|
||||
MsgText.JournalEncryptedTo,
|
||||
MsgStyle.NORMAL,
|
||||
{"path": args.filename or new_journal.config["journal"]},
|
||||
{"path": args.filename or journal.config["journal"]},
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -142,19 +144,20 @@ def postconfig_decrypt(
|
|||
"""Decrypts into new file. If filename is not set, we encrypt the journal file itself."""
|
||||
from jrnl.config import update_config
|
||||
from jrnl.install import save_config
|
||||
from jrnl.Journal import PlainJournal
|
||||
from jrnl.Journal import open_journal
|
||||
|
||||
journal = open_journal(args.journal_name, config)
|
||||
journal.config["encrypt"] = False
|
||||
|
||||
new_journal = PlainJournal.from_journal(journal)
|
||||
new_journal.write(args.filename)
|
||||
logging.debug("Clearing encryption method...")
|
||||
journal.config["encrypt"] = False
|
||||
journal.encryption_method = None
|
||||
|
||||
journal.write(args.filename)
|
||||
print_msg(
|
||||
Message(
|
||||
MsgText.JournalDecryptedTo,
|
||||
MsgStyle.NORMAL,
|
||||
{"path": args.filename or new_journal.config["journal"]},
|
||||
{"path": args.filename or journal.config["journal"]},
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue