Move error for too many wrong passwords into new handling

This commit is contained in:
Jonathan Wren 2022-02-19 18:07:13 -08:00
parent 101963bba6
commit aa9343a75c
2 changed files with 17 additions and 14 deletions

View file

@ -21,6 +21,9 @@ from .Journal import Journal
from .Journal import LegacyJournal from .Journal import LegacyJournal
from .prompt import create_password from .prompt import create_password
from jrnl.exception import JrnlException
from jrnl.exception import JrnlExceptionMessage
def make_key(password): def make_key(password):
password = password.encode("utf-8") password = password.encode("utf-8")
@ -53,11 +56,11 @@ def decrypt_content(
password = getpass.getpass() password = getpass.getpass()
result = decrypt_func(password) result = decrypt_func(password)
attempt += 1 attempt += 1
if result is not None:
return result if result is None:
else: raise JrnlException(JrnlExceptionMessage.PasswordMaxTriesExceeded)
print("Extremely wrong password.", file=sys.stderr)
sys.exit(1) return result
class EncryptedJournal(Journal): class EncryptedJournal(Journal):
@ -121,15 +124,11 @@ class EncryptedJournal(Journal):
@classmethod @classmethod
def from_journal(cls, other: Journal): def from_journal(cls, other: Journal):
new_journal = super().from_journal(other) new_journal = super().from_journal(other)
try: new_journal.password = (
new_journal.password = ( other.password
other.password if hasattr(other, "password")
if hasattr(other, "password") else create_password(other.name)
else create_password(other.name) )
)
except KeyboardInterrupt:
print("[Interrupted while creating new journal]", file=sys.stderr)
sys.exit(1)
return new_journal return new_journal

View file

@ -76,6 +76,10 @@ class JrnlExceptionMessage(Enum):
{config_file} {config_file}
""" """
PasswordMaxTriesExceeded = """
Too many attempts with wrong password.
"""
SomeTest = """ SomeTest = """
Some error or something Some error or something