From 41a5af533d91db2b873fd28cad0b2a3fceff49f6 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sun, 25 Sep 2022 15:52:14 -0700 Subject: [PATCH] update the upgrade process for new encryption classes --- jrnl/encryption/NoEncryption.py | 7 +++++-- jrnl/upgrade.py | 11 +++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/jrnl/encryption/NoEncryption.py b/jrnl/encryption/NoEncryption.py index 60475a7a..1c7d2c5d 100644 --- a/jrnl/encryption/NoEncryption.py +++ b/jrnl/encryption/NoEncryption.py @@ -10,5 +10,8 @@ class NoEncryption(BaseEncryption): def _encrypt(self, text: str) -> str: return text - def _decrypt(self, text: str) -> str: - return text + def _decrypt(self, text: bytes | str) -> str: + result = text + if isinstance(result, bytes): + result = result.decode(self._encoding) + return result diff --git a/jrnl/upgrade.py b/jrnl/upgrade.py index e9f1c136..1764a94a 100644 --- a/jrnl/upgrade.py +++ b/jrnl/upgrade.py @@ -134,8 +134,15 @@ def upgrade_jrnl(config_path): ) logging.debug(f"Clearing encryption method for '{journal_name}' journal") - old_journal.encryption_method = None - all_journals.append(old_journal) + + # Update the encryption method + new_journal = Journal.PlainJournal.from_journal(old_journal) + new_journal.config["encrypt"] = "jrnlv2" + new_journal._get_encryption_method() + # Copy over password (jrnlv1 only supported password-based encryption) + new_journal.encryption_method.password = old_journal.encryption_method.password + + all_journals.append(new_journal) for journal_name, path in plain_journals.items(): print_msg(