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

View file

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