Move unlock_luks2_dev() (#4234)

This commit is contained in:
codefiles 2026-02-16 15:35:25 -05:00 committed by GitHub
parent 35c2ff3ef5
commit 083a73eab1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 18 deletions

View File

@ -10,7 +10,7 @@ from parted import Device, Disk, DiskException, FileSystem, Geometry, IOExceptio
from ..command import SysCommand, SysCommandWorker from ..command import SysCommand, SysCommandWorker
from ..exceptions import DiskError, SysCallError, UnknownFilesystemFormat from ..exceptions import DiskError, SysCallError, UnknownFilesystemFormat
from ..luks import Luks2 from ..luks import Luks2, unlock_luks2_dev
from ..models.device import ( from ..models.device import (
DEFAULT_ITER_TIME, DEFAULT_ITER_TIME,
BDevice, BDevice,
@ -658,7 +658,7 @@ class DeviceHandler:
if not part_mod.mapper_name: if not part_mod.mapper_name:
raise ValueError('No device path specified for modification') raise ValueError('No device path specified for modification')
luks_handler = self.unlock_luks2_dev( luks_handler = unlock_luks2_dev(
part_mod.safe_dev_path, part_mod.safe_dev_path,
part_mod.mapper_name, part_mod.mapper_name,
enc_conf.encryption_password, enc_conf.encryption_password,
@ -691,19 +691,6 @@ class DeviceHandler:
if luks_handler is not None and luks_handler.mapper_dev is not None: if luks_handler is not None and luks_handler.mapper_dev is not None:
luks_handler.lock() luks_handler.lock()
def unlock_luks2_dev(
self,
dev_path: Path,
mapper_name: str,
enc_password: Password | None,
) -> Luks2:
luks_handler = Luks2(dev_path, mapper_name=mapper_name, password=enc_password)
if not luks_handler.is_unlocked():
luks_handler.unlock()
return luks_handler
def umount_all_existing(self, device_path: Path) -> None: def umount_all_existing(self, device_path: Path) -> None:
debug(f'Unmounting all existing partitions: {device_path}') debug(f'Unmounting all existing partitions: {device_path}')

View File

@ -41,7 +41,7 @@ from .command import SysCommand, run
from .exceptions import DiskError, HardwareIncompatibilityError, RequirementError, ServiceException, SysCallError from .exceptions import DiskError, HardwareIncompatibilityError, RequirementError, ServiceException, SysCallError
from .hardware import SysInfo from .hardware import SysInfo
from .locale.utils import verify_keyboard_layout, verify_x11_keyboard_layout from .locale.utils import verify_keyboard_layout, verify_x11_keyboard_layout
from .luks import Luks2 from .luks import Luks2, unlock_luks2_dev
from .mirrors import MirrorListHandler from .mirrors import MirrorListHandler
from .models.bootloader import Bootloader from .models.bootloader import Bootloader
from .models.locale import LocaleConfiguration from .models.locale import LocaleConfiguration
@ -317,7 +317,7 @@ class Installer:
partitions: list[PartitionModification], partitions: list[PartitionModification],
) -> dict[PartitionModification, Luks2]: ) -> dict[PartitionModification, Luks2]:
return { return {
part_mod: device_handler.unlock_luks2_dev( part_mod: unlock_luks2_dev(
part_mod.dev_path, part_mod.dev_path,
part_mod.mapper_name, part_mod.mapper_name,
self._disk_encryption.encryption_password, self._disk_encryption.encryption_password,
@ -344,7 +344,7 @@ class Installer:
lvm_volumes: list[LvmVolume], lvm_volumes: list[LvmVolume],
) -> dict[LvmVolume, Luks2]: ) -> dict[LvmVolume, Luks2]:
return { return {
vol: device_handler.unlock_luks2_dev( vol: unlock_luks2_dev(
vol.dev_path, vol.dev_path,
vol.mapper_name, vol.mapper_name,
self._disk_encryption.encryption_password, self._disk_encryption.encryption_password,

View File

@ -237,3 +237,16 @@ class Luks2:
uuid = self._get_luks_uuid() uuid = self._get_luks_uuid()
row = f'{self.mapper_name} UUID={uuid} {key_file} {opt}\n' row = f'{self.mapper_name} UUID={uuid} {key_file} {opt}\n'
crypttab.write(row) crypttab.write(row)
def unlock_luks2_dev(
dev_path: Path,
mapper_name: str,
enc_password: Password | None,
) -> Luks2:
luks_handler = Luks2(dev_path, mapper_name=mapper_name, password=enc_password)
if not luks_handler.is_unlocked():
luks_handler.unlock()
return luks_handler