Trait Session

Source
pub trait Session:
    'static
    + Sync
    + Send
    + Unpin {
Show 13 methods // Provided methods fn request_identities<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Identity>, AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn sign<'life0, 'async_trait>( &'life0 mut self, _request: SignRequest, ) -> Pin<Box<dyn Future<Output = Result<Signature, AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn add_identity<'life0, 'async_trait>( &'life0 mut self, _identity: AddIdentity, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn add_identity_constrained<'life0, 'async_trait>( &'life0 mut self, _identity: AddIdentityConstrained, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn remove_identity<'life0, 'async_trait>( &'life0 mut self, _identity: RemoveIdentity, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn remove_all_identities<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn add_smartcard_key<'life0, 'async_trait>( &'life0 mut self, _key: SmartcardKey, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn add_smartcard_key_constrained<'life0, 'async_trait>( &'life0 mut self, _key: AddSmartcardKeyConstrained, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn remove_smartcard_key<'life0, 'async_trait>( &'life0 mut self, _key: SmartcardKey, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn lock<'life0, 'async_trait>( &'life0 mut self, _key: String, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn unlock<'life0, 'async_trait>( &'life0 mut self, _key: String, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn extension<'life0, 'async_trait>( &'life0 mut self, _extension: Extension, ) -> Pin<Box<dyn Future<Output = Result<Option<Extension>, AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn handle<'life0, 'async_trait>( &'life0 mut self, message: Request, ) -> Pin<Box<dyn Future<Output = Result<Response, AgentError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... }
}
Expand description

Represents one active SSH connection.

This type is implemented by agents that want to handle incoming SSH agent connections.

§Examples

The following examples shows the most minimal Session implementation: one that returns a list of public keys that it manages and signs all incoming signing requests.

Note that the MyAgent struct is cloned for all new sessions (incoming connections). If the cloning needs special behavior implementing Clone manually is a viable approach. If the newly created sessions require information from the underlying socket it is advisable to implement the Agent trait.

use ssh_agent_lib::{agent::Session, error::AgentError};
use ssh_agent_lib::proto::{Identity, SignRequest};
use ssh_key::{Algorithm, Signature};

#[derive(Default, Clone)]
struct MyAgent;

#[ssh_agent_lib::async_trait]
impl Session for MyAgent {
    async fn request_identities(&mut self) -> Result<Vec<Identity>, AgentError> {
        Ok(vec![ /* public keys that this agent knows of */ ])
    }

    async fn sign(&mut self, request: SignRequest) -> Result<Signature, AgentError> {
        // get the signature by signing `request.data`
        let signature = vec![];
        Ok(Signature::new(
             Algorithm::new("algorithm").map_err(AgentError::other)?,
             signature,
        ).map_err(AgentError::other)?)
    }
}

Provided Methods§

Source

fn request_identities<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Identity>, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Request a list of keys managed by this session.

Source

fn sign<'life0, 'async_trait>( &'life0 mut self, _request: SignRequest, ) -> Pin<Box<dyn Future<Output = Result<Signature, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Perform a private key signature operation.

Source

fn add_identity<'life0, 'async_trait>( &'life0 mut self, _identity: AddIdentity, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add a private key to the agent.

Source

fn add_identity_constrained<'life0, 'async_trait>( &'life0 mut self, _identity: AddIdentityConstrained, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add a private key to the agent with a set of constraints.

Source

fn remove_identity<'life0, 'async_trait>( &'life0 mut self, _identity: RemoveIdentity, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove private key from an agent.

Source

fn remove_all_identities<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove all keys from an agent.

Source

fn add_smartcard_key<'life0, 'async_trait>( &'life0 mut self, _key: SmartcardKey, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add a key stored on a smartcard.

Source

fn add_smartcard_key_constrained<'life0, 'async_trait>( &'life0 mut self, _key: AddSmartcardKeyConstrained, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add a key stored on a smartcard with a set of constraints.

Source

fn remove_smartcard_key<'life0, 'async_trait>( &'life0 mut self, _key: SmartcardKey, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove a smartcard key from the agent.

Source

fn lock<'life0, 'async_trait>( &'life0 mut self, _key: String, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Temporarily lock the agent with a password.

Source

fn unlock<'life0, 'async_trait>( &'life0 mut self, _key: String, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Unlock the agent with a password.

Source

fn extension<'life0, 'async_trait>( &'life0 mut self, _extension: Extension, ) -> Pin<Box<dyn Future<Output = Result<Option<Extension>, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Invoke a custom, vendor-specific extension on the agent.

Source

fn handle<'life0, 'async_trait>( &'life0 mut self, message: Request, ) -> Pin<Box<dyn Future<Output = Result<Response, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a raw SSH agent request and return agent response.

Note that it is preferable to use high-level functions instead of this function. This function should be overridden only for custom messages, outside of the SSH agent protocol specification.

Implementors§

Source§

impl<Stream> Session for Client<Stream>
where Stream: Debug + AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,