Skip to main content

purple_ssh/
ssh_context.rs

1use std::path::{Path, PathBuf};
2
3/// Common SSH connection context passed to remote operations.
4pub struct SshContext<'a> {
5    pub alias: &'a str,
6    pub config_path: &'a Path,
7    pub askpass: Option<&'a str>,
8    /// Password typed in the TUI for this session only. Reaches ssh through
9    /// the one-shot askpass channel and is never written to disk.
10    pub session_password: Option<&'a str>,
11    pub bw_session: Option<&'a str>,
12    pub has_tunnel: bool,
13    /// Set only by a retry that follows the trust dialog: ssh runs with
14    /// `StrictHostKeyChecking=accept-new` for that one run so the host key
15    /// is recorded on first contact.
16    pub trust_new_host_key: bool,
17    /// Security key PINs this run may hand out plus the flow that asks for
18    /// a missing one.
19    pub security_key: &'a crate::security_key::SecurityKeyRun,
20    pub env: &'a crate::runtime::env::Env,
21}
22
23/// Owned variant for spawning into threads.
24pub struct OwnedSshContext {
25    pub alias: String,
26    pub config_path: PathBuf,
27    pub askpass: Option<String>,
28    pub session_password: Option<String>,
29    pub bw_session: Option<String>,
30    pub has_tunnel: bool,
31    pub trust_new_host_key: bool,
32    pub security_key: crate::security_key::SecurityKeyRun,
33    pub env: std::sync::Arc<crate::runtime::env::Env>,
34}
35
36impl OwnedSshContext {
37    /// Borrow every field for a synchronous call inside the worker thread.
38    pub fn borrow(&self) -> SshContext<'_> {
39        SshContext {
40            alias: &self.alias,
41            config_path: &self.config_path,
42            askpass: self.askpass.as_deref(),
43            session_password: self.session_password.as_deref(),
44            bw_session: self.bw_session.as_deref(),
45            has_tunnel: self.has_tunnel,
46            trust_new_host_key: self.trust_new_host_key,
47            security_key: &self.security_key,
48            env: &self.env,
49        }
50    }
51}