tape: avoid error when clearing encryption key

Simply ignore clear request when sg_spin_data_encryption_caps fails.
Assume those are tapes without hardware encryption support.
This commit is contained in:
Dietmar Maurer 2021-01-23 10:20:43 +01:00
parent 44a5f38bc4
commit 979dccc7ec

View File

@ -33,7 +33,16 @@ pub fn set_encryption<F: AsRawFd>(
key: Option<[u8; 32]>,
) -> Result<(), Error> {
let data = sg_spin_data_encryption_caps(file)?;
let data = match sg_spin_data_encryption_caps(file) {
Ok(data) => data,
Err(err) if key.is_none() => {
/// Assume device does not support HW encryption
/// We can simply ignore the clear key request
return Ok(());
}
Err(err) => return Err(err),
};
let algorithm_index = decode_spin_data_encryption_caps(&data)?;
sg_spout_set_encryption(file, algorithm_index, key)?;