Skip to content

Commit cc9af09

Browse files
authored
Merge pull request #3355 from mulkieran/dont-panic-if-no-unlock
Dont panic if no unlock method available
2 parents c006291 + 8679644 commit cc9af09

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/engine/strat_engine/backstore/crypt/handle.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,15 @@ impl CryptHandle {
205205
.and_then(|path| clevis_info_from_metadata(&mut device).map(|ci| (path, ci)))
206206
.and_then(|(_, clevis_info)| {
207207
let encryption_info =
208-
EncryptionInfo::from_options((encryption_info.key_description().cloned(), clevis_info))
209-
.expect("Encrypted device must be provided encryption parameters");
208+
if let Some(info) = EncryptionInfo::from_options((encryption_info.key_description().cloned(), clevis_info)) {
209+
info
210+
} else {
211+
return Err(StratisError::Msg(format!(
212+
"No valid encryption method that can be used to unlock device {} found after initialization",
213+
physical_path.display()
214+
)));
215+
};
216+
210217
let device_path = DevicePath::new(physical_path)?;
211218
let devno = get_devno_from_path(physical_path)?;
212219
Ok(CryptHandle::new(

src/engine/strat_engine/backstore/crypt/shared.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,15 @@ pub fn load_crypt_metadata(
402402
};
403403
let clevis_info = clevis_info_from_metadata(device)?;
404404

405-
let encryption_info = EncryptionInfo::from_options((key_description, clevis_info))
406-
.expect("Must have at least one unlock method");
405+
let encryption_info =
406+
if let Some(info) = EncryptionInfo::from_options((key_description, clevis_info)) {
407+
info
408+
} else {
409+
return Err(StratisError::Msg(format!(
410+
"No valid encryption method that can be used to unlock device {} found",
411+
physical_path.display()
412+
)));
413+
};
407414

408415
let path = vec![DEVICEMAPPER_PATH, &activation_name.to_string()]
409416
.into_iter()

0 commit comments

Comments
 (0)