pub struct Agent { /* private fields */ }Expand description
Handle to a running SSH agent.
Thin wrapper over ssh_agent_lib::blocking::Client that translates
its error type into GitwayError and the protocol structs into
more convenient Gitway types.
Implementations§
Source§impl Agent
impl Agent
Sourcepub fn from_env() -> Result<Self, GitwayError>
pub fn from_env() -> Result<Self, GitwayError>
Connects to the agent at $SSH_AUTH_SOCK.
§Errors
Returns GitwayError::invalid_config when $SSH_AUTH_SOCK is
unset or empty, and GitwayError::from an I/O error when the
socket cannot be opened.
Sourcepub fn connect(path: &Path) -> Result<Self, GitwayError>
pub fn connect(path: &Path) -> Result<Self, GitwayError>
Connects to the agent socket at path.
§Errors
Returns GitwayError::from the underlying I/O error when the
socket cannot be opened.
Sourcepub fn list(&mut self) -> Result<Vec<Identity>, GitwayError>
pub fn list(&mut self) -> Result<Vec<Identity>, GitwayError>
Returns the identities currently loaded into the agent.
§Errors
Returns GitwayError on agent protocol or I/O failure.
Sourcepub fn add(
&mut self,
key: &PrivateKey,
lifetime: Option<Duration>,
confirm: bool,
) -> Result<(), GitwayError>
pub fn add( &mut self, key: &PrivateKey, lifetime: Option<Duration>, confirm: bool, ) -> Result<(), GitwayError>
Adds an identity to the agent.
lifetime (if Some) caps how long the agent retains the key;
once elapsed the agent silently evicts it — matching
ssh-add -t <seconds>. confirm asks the agent to prompt the
user interactively before each signing operation (agent-dependent).
§Errors
Returns GitwayError on agent protocol or I/O failure.
Sourcepub fn remove(&mut self, public_key: &PublicKey) -> Result<(), GitwayError>
pub fn remove(&mut self, public_key: &PublicKey) -> Result<(), GitwayError>
Removes a single identity from the agent.
§Errors
Returns GitwayError when the agent rejects the request (e.g.
identity not loaded) or on I/O failure.
Sourcepub fn remove_all(&mut self) -> Result<(), GitwayError>
pub fn remove_all(&mut self) -> Result<(), GitwayError>
Removes all identities from the agent (matches ssh-add -D).
§Errors
Returns GitwayError on agent protocol or I/O failure.
Sourcepub fn lock(
&mut self,
passphrase: &Zeroizing<String>,
) -> Result<(), GitwayError>
pub fn lock( &mut self, passphrase: &Zeroizing<String>, ) -> Result<(), GitwayError>
Locks the agent with a passphrase (matches ssh-add -x).
The agent refuses all signing requests until unlock
is called with the same passphrase.
§Errors
Returns GitwayError when the agent rejects the passphrase or
on I/O failure. The passphrase string passed through to
ssh-agent-lib is a fresh String derived from passphrase; the
caller’s Zeroizing buffer is not moved.
Sourcepub fn unlock(
&mut self,
passphrase: &Zeroizing<String>,
) -> Result<(), GitwayError>
pub fn unlock( &mut self, passphrase: &Zeroizing<String>, ) -> Result<(), GitwayError>
Unlocks a previously-locked agent (matches ssh-add -X).
§Errors
Returns GitwayError when the agent rejects the passphrase or
on I/O failure.