From 0a03f1c84ef0867f08744dcd856e30e27a4ed70a Mon Sep 17 00:00:00 2001 From: Fred Gobry Date: Mon, 25 May 2026 10:56:18 -0400 Subject: [PATCH] crypto: Handle default `SSH_AUTH_SOCK` on Windows On Windows, SSH Agents commonly use a named pipe with a global default name. This patch is to give users a more streamline experience as they will not need to set the environment variable manually anymore. --- crates/radicle-crypto/src/ssh/agent.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/radicle-crypto/src/ssh/agent.rs b/crates/radicle-crypto/src/ssh/agent.rs index 39fec41e..fe48bb8d 100644 --- a/crates/radicle-crypto/src/ssh/agent.rs +++ b/crates/radicle-crypto/src/ssh/agent.rs @@ -60,13 +60,19 @@ impl Agent { pub fn connect() -> Result { const SSH_AUTH_SOCK: &str = "SSH_AUTH_SOCK"; - let path = - PathBuf::from( - std::env::var(SSH_AUTH_SOCK).map_err(|err| ConnectError::EnvVar { - var: SSH_AUTH_SOCK.to_string(), - source: err, - })?, - ); + let path = match std::env::var(SSH_AUTH_SOCK) { + Ok(path) => Ok(PathBuf::from(path)), + #[cfg(windows)] + Err(VarError::NotPresent) => { + // Windows exposes the SSH Agent on a default named pipe. + const DEFAULT_SSH_AGENT_PIPE: &str = "\\\\.\\pipe\\openssh-ssh-agent"; + Ok(PathBuf::from(DEFAULT_SSH_AGENT_PIPE)) + } + Err(err) => Err(ConnectError::EnvVar { + var: SSH_AUTH_SOCK.to_string(), + source: err, + }), + }?; let client = Client::new( Stream::connect(&path).map_err(|err| ConnectError::Agent(AgentError::IO(err)))?,