Skip to main content

confium_pkcs11_server/
slot.rs

1//! PKCS#11 slot model.
2
3use serde::{Deserialize, Serialize};
4
5/// A PKCS#11 slot identifier. Maps 1:1 to a Confium quorum.
6#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub struct SlotId(pub u64);
8
9/// Slot info (per PKCS#11 `CK_SLOT_INFO`).
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct SlotInfo {
12    /// Slot description (32 bytes in real PKCS#11, here as String).
13    pub description: String,
14    /// Hardware manufacturer ID.
15    pub manufacturer: String,
16    /// True if a token is present.
17    pub token_present: bool,
18    /// True if hardware (vs software slot).
19    pub hardware: bool,
20    /// Associated quorum ID.
21    pub quorum_id: String,
22}
23
24impl SlotInfo {
25    /// Construct slot info for a Confium quorum.
26    pub fn for_quorum(quorum_id: impl Into<String>) -> Self {
27        let qid = quorum_id.into();
28        Self {
29            description: format!("Confium quorum: {qid}"),
30            manufacturer: "Confium Project".into(),
31            token_present: true,
32            hardware: false,
33            quorum_id: qid,
34        }
35    }
36}