From 979dccc7ecc60a6a156616af26436000ab6d7676 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 23 Jan 2021 10:20:43 +0100 Subject: [PATCH] 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. --- src/tape/drive/encryption.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tape/drive/encryption.rs b/src/tape/drive/encryption.rs index a71ae2ff..0f1d3bd3 100644 --- a/src/tape/drive/encryption.rs +++ b/src/tape/drive/encryption.rs @@ -33,7 +33,16 @@ pub fn set_encryption( 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)?;