Skip to main content

signstar_host/configure/host/
all_backends.rs

1//! Functionality when support for all backends is compiled in.
2
3use log::info;
4
5use crate::{
6    Error,
7    configure::{ConfigurationResult, HostConfiguration},
8};
9
10impl<'config> HostConfiguration<'config> {
11    /// Syncs the Signstar host with its configuration.
12    ///
13    /// # Errors
14    ///
15    /// Returns an error, if
16    ///
17    /// - the syncing of NetHSM backends fails
18    /// - the syncing of YubiHSM2 backends fails
19    pub fn sync(&self) -> Result<ConfigurationResult, Error> {
20        info!("Sync the Signstar host with its configuration.");
21
22        let nethsm_config_result = self.sync_nethsm()?;
23        let yubihsm_config_result = self.sync_yubihsm2()?;
24
25        if matches!(
26            nethsm_config_result,
27            ConfigurationResult::MissingConfigurationForBackend
28        ) && matches!(
29            yubihsm_config_result,
30            ConfigurationResult::MissingConfigurationForBackend
31        ) {
32            return Ok(ConfigurationResult::MissingConfigurationForBackend);
33        }
34
35        if !matches!(
36            nethsm_config_result,
37            ConfigurationResult::SyncSucceeded
38                | ConfigurationResult::MissingConfigurationForBackend
39        ) {
40            return Ok(nethsm_config_result);
41        }
42
43        if !matches!(
44            yubihsm_config_result,
45            ConfigurationResult::SyncSucceeded
46                | ConfigurationResult::MissingConfigurationForBackend
47        ) {
48            return Ok(yubihsm_config_result);
49        }
50
51        Ok(ConfigurationResult::SyncSucceeded)
52    }
53}