From 289ebd549770dc20bc9ea53c2e0282dc5ac7ca6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 5 Sep 2024 17:09:03 +0200 Subject: [PATCH] Add check that slots have at least one instance --- pkcs11/src/config/initialization.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkcs11/src/config/initialization.rs b/pkcs11/src/config/initialization.rs index b156b824..a10b6d3d 100644 --- a/pkcs11/src/config/initialization.rs +++ b/pkcs11/src/config/initialization.rs @@ -27,6 +27,8 @@ pub enum InitializationError { NoCerts, #[error("No operator or administrator for slot: {0}")] NoUser(String), + #[error("No instance given for a slot")] + NoInstance, } pub fn initialize_with_configs( @@ -288,7 +290,11 @@ fn slot_from_config(slot: &SlotConfig) -> Result { }; Ok(api_config) }) - .collect::>()?; + .collect::, InitializationError>>()?; + if instances.is_empty() { + error!("Slot without any instance configured"); + return Err(InitializationError::NoInstance); + } Ok(Slot { _description: slot.description.clone(),