inline all messages

This commit is contained in:
timeshifter
2022-12-06 15:15:43 +01:00
parent 28963c3e64
commit 530a1e090a
6 changed files with 13 additions and 30 deletions
+2 -3
View File
@@ -3,7 +3,6 @@ from __future__ import annotations
from pathlib import Path
from uuid import UUID
from .messages import ALREADY_DECRYPTED, NOT_DECRYPTED
from .commands.cryptsetup import Cryptsetup
from .misc import DISK_BY_UUID
@@ -18,7 +17,7 @@ class Disk:
def decrypt(self) -> None:
"""Open a LUKS-encrypted disk with `cryptsetup`. Silently pass if it was already decrypted."""
if self._decrypted:
raise ValueError(ALREADY_DECRYPTED, self._name)
raise ValueError("Cannot decrypt, already decrypted", self._name)
self._was_already_decrypted = Cryptsetup.decrypt(self._path, self._mapper_entry)
self._decrypted = True
@@ -35,7 +34,7 @@ class Disk:
def encrypt(self) -> None:
"""Close a LUKS-encrypted container with `cryptsetup`."""
if not self._decrypted:
raise ValueError(NOT_DECRYPTED, self._name)
raise ValueError("Cannot encrypt, not decrypted", self._name)
if self._was_already_decrypted:
return
Cryptsetup.encrypt(self._mapper_entry)