Skip to main content

Agent

Struct Agent 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn sign( &mut self, public_key: &PublicKey, data: &[u8], ) -> Result<Signature, GitwayError>

Asks the agent to sign data with the loaded private key whose public counterpart matches public_key.

For RSA keys the request carries SSH_AGENT_RSA_SHA2_512 (flag = 4) so the agent returns an rsa-sha2-512 signature — matching OpenSSH’s -Y sign default and the one SSHSIG verifiers expect. Ed25519 and ECDSA ignore the flag field; the algorithm is fixed by the key type.

SHA-1 ssh-rsa downgrade (flag = 0 on an RSA key) is not requested here — OpenSSH 8.2+ (Jan 2020) always asks for SHA-2, and our own daemon rejects SHA-1 RSA requests in crate::agent::daemon.

§Errors

Returns GitwayError when the agent rejects the request (commonly because the key is not loaded, the agent is locked, or a --confirm prompt was denied) or on I/O failure.

Trait Implementations§

Source§

impl Debug for Agent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Agent

§

impl RefUnwindSafe for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnsafeUnpin for Agent

§

impl UnwindSafe for Agent

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V