1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::{util::run_ssh2_fn, Error};
use smol::Async;
use ssh2::{self, PublicKey};
use std::{convert::From, net::TcpStream, sync::Arc};
pub struct Agent {
inner: ssh2::Agent,
stream: Arc<Async<TcpStream>>,
}
impl Agent {
pub(crate) fn new(agent: ssh2::Agent, stream: Arc<Async<TcpStream>>) -> Self {
Self {
inner: agent,
stream,
}
}
pub async fn connect(&mut self) -> Result<(), Error> {
run_ssh2_fn(&self.stream.clone(), || self.inner.connect()).await
}
pub async fn disconnect(&mut self) -> Result<(), Error> {
run_ssh2_fn(&self.stream.clone(), || self.inner.disconnect()).await
}
pub fn list_identities(&mut self) -> Result<(), Error> {
self.inner.list_identities().map_err(From::from)
}
pub fn identities(&self) -> Result<Vec<PublicKey>, Error> {
self.inner.identities().map_err(From::from)
}
pub async fn userauth(&self, username: &str, identity: &PublicKey) -> Result<(), Error> {
run_ssh2_fn(&self.stream.clone(), || {
self.inner.userauth(username, identity)
})
.await
}
}