Skip to main content

signstar_common/
backend.rs

1//! Common components for any type of backend.
2
3use std::collections::HashMap;
4
5/// The [os-release] `ID` for Arch Linux.
6///
7/// [os-release]: https://man.archlinux.org/man/os-release.5
8const OS_ARCH: &str = "arch";
9
10/// The Unix groups required to connect to a YubiHSM2 backend on an Arch Linux system.
11const ARCH_YUBIHSM2_GROUPS: &[&str] = &["_yubihsm2"];
12
13/// The type of a supported HSM backend.
14#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
15#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
16pub enum BackendType {
17    /// The NetHSM backend.
18    NetHsm,
19
20    /// The YubiHSM2 backend.
21    YubiHsm2,
22}
23
24impl BackendType {
25    /// Returns the required Unix groups for an operating system to connect to a given backend.
26    ///
27    /// The returned [`HashMap`] uses the `ID` of an OS in the [os-release] format as key.
28    ///
29    /// [os-release]: https://man.archlinux.org/man/os-release.5
30    pub fn client_unix_groups(&self) -> HashMap<&str, &[&str]> {
31        match self {
32            Self::NetHsm => HashMap::new(),
33            Self::YubiHsm2 => HashMap::from_iter([(OS_ARCH, ARCH_YUBIHSM2_GROUPS)]),
34        }
35    }
36}