Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/models/disk_encryption.py
blob: 3edab93e56df02c13ea9dfe1aa67892aa23ead9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from dataclasses import dataclass, field
from enum import Enum, auto
from typing import Optional, List, Dict, TYPE_CHECKING, Any

from ..hsm.fido import Fido2Device

if TYPE_CHECKING:
	_: Any


class EncryptionType(Enum):
	Partition = auto()
	# FullDiskEncryption = auto()

	@classmethod
	def _encryption_type_mapper(cls) -> Dict[str, 'EncryptionType']:
		return {
			# str(_('Full disk encryption')): EncryptionType.FullDiskEncryption,
			str(_('Partition encryption')): EncryptionType.Partition
		}

	@classmethod
	def text_to_type(cls, text: str) -> 'EncryptionType':
		mapping = cls._encryption_type_mapper()
		return mapping[text]

	@classmethod
	def type_to_text(cls, type_: 'EncryptionType') -> str:
		mapping = cls._encryption_type_mapper()
		type_to_text = {type_: text for text, type_ in mapping.items()}
		return type_to_text[type_]


@dataclass
class DiskEncryption:
	encryption_type: EncryptionType = EncryptionType.Partition
	encryption_password: str = ''
	partitions: List[str] = field(default_factory=list)
	hsm_device: Optional[Fido2Device] = None

	def generate_encryption_file(self, partition) -> bool:
		return partition in self.partitions and partition['mountpoint'] != '/'