@@ -91,6 +91,43 @@ impl ListeningSocket for NamedPipeListener {
91
91
///
92
92
/// This type is implemented by agents that want to handle incoming SSH agent
93
93
/// connections.
94
+ ///
95
+ /// # Examples
96
+ ///
97
+ /// The following examples shows the most minimal [`Session`]
98
+ /// implementation: one that returns a list of public keys that it
99
+ /// manages and signs all incoming signing requests.
100
+ ///
101
+ /// Note that the `MyAgent` struct is cloned for all new sessions
102
+ /// (incoming connections). If the cloning needs special behavior
103
+ /// implementing [`Clone`] manually is a viable approach. If the newly
104
+ /// created sessions require information from the underlying socket it
105
+ /// is advisable to implement the [`Agent`] trait.
106
+ ///
107
+ /// ```
108
+ /// use ssh_agent_lib::{agent::Session, error::AgentError};
109
+ /// use ssh_agent_lib::proto::{Identity, SignRequest};
110
+ /// use ssh_key::{Algorithm, Signature};
111
+ ///
112
+ /// #[derive(Default, Clone)]
113
+ /// struct MyAgent;
114
+ ///
115
+ /// #[ssh_agent_lib::async_trait]
116
+ /// impl Session for MyAgent {
117
+ /// async fn request_identities(&mut self) -> Result<Vec<Identity>, AgentError> {
118
+ /// Ok(vec![ /* public keys that this agent knows of */ ])
119
+ /// }
120
+ ///
121
+ /// async fn sign(&mut self, request: SignRequest) -> Result<Signature, AgentError> {
122
+ /// // get the signature by signing `request.data`
123
+ /// let signature = vec![];
124
+ /// Ok(Signature::new(
125
+ /// Algorithm::new("algorithm").map_err(AgentError::other)?,
126
+ /// signature,
127
+ /// ).map_err(AgentError::other)?)
128
+ /// }
129
+ /// }
130
+ /// ```
94
131
#[ async_trait]
95
132
pub trait Session : ' static + Sync + Send + Unpin {
96
133
/// Request a list of keys managed by this session.
0 commit comments