Skip to main content

purple_ssh/app/
vault.rs

1use std::collections::{HashMap, HashSet};
2use std::sync::atomic::AtomicBool;
3use std::sync::{Arc, Mutex};
4
5/// Vault SSH certificate and signing state.
6pub struct VaultState {
7    /// Cached vault certificate status per host alias.
8    /// Tuple: (check timestamp, status, cert file mtime at check time).
9    pub cert_cache: HashMap<
10        String,
11        (
12            std::time::Instant,
13            crate::vault_ssh::CertStatus,
14            Option<std::time::SystemTime>,
15        ),
16    >,
17    /// Aliases currently being checked for cert status (prevent duplicate checks).
18    pub cert_checks_in_flight: HashSet<String>,
19    /// Side-channel warning from cert-cache cleanup.
20    pub cleanup_warning: Option<String>,
21    /// Cancel flag for the V-key vault signing background thread.
22    pub signing_cancel: Option<Arc<AtomicBool>>,
23    /// JoinHandle for the V-key vault signing background thread.
24    pub sign_thread: Option<std::thread::JoinHandle<()>>,
25    /// Aliases currently being signed by the bulk V-key loop.
26    pub sign_in_flight: Arc<Mutex<HashSet<String>>>,
27    /// Deferred config write from VaultSignAllDone (guarded while forms are open).
28    pub pending_config_write: bool,
29}
30
31impl Default for VaultState {
32    fn default() -> Self {
33        Self {
34            cert_cache: HashMap::new(),
35            cert_checks_in_flight: HashSet::new(),
36            cleanup_warning: None,
37            signing_cancel: None,
38            sign_thread: None,
39            sign_in_flight: Arc::new(Mutex::new(HashSet::new())),
40            pending_config_write: false,
41        }
42    }
43}