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)]
15pub enum BackendType {
16    /// The NetHSM backend.
17    NetHsm,
18
19    /// The YubiHSM2 backend.
20    YubiHsm2,
21}
22
23impl BackendType {
24    /// Returns the required Unix groups for an operating system to connect to a given backend.
25    ///
26    /// The returned [`HashMap`] uses the `ID` of an OS in the [os-release] format as key.
27    ///
28    /// [os-release]: https://man.archlinux.org/man/os-release.5
29    pub fn client_unix_groups(&self) -> HashMap<&str, &[&str]> {
30        match self {
31            Self::NetHsm => HashMap::new(),
32            Self::YubiHsm2 => HashMap::from_iter([(OS_ARCH, ARCH_YUBIHSM2_GROUPS)]),
33        }
34    }
35}