t_ssh_client/
lib.rs

1mod client;
2mod error;
3
4use std::future;
5use thrussh_keys::key;
6
7pub use client::*;
8pub use error::ClientError;
9
10#[derive(Default)]
11pub struct Output {
12    pub stdout: Vec<u8>,
13    pub stderr: Vec<u8>,
14    pub code: Option<u32>,
15}
16
17impl Output {
18    pub fn stdout_string(&self) -> String {
19        String::from_utf8_lossy(&self.stdout).into()
20    }
21
22    pub fn stderr_string(&self) -> String {
23        String::from_utf8_lossy(&self.stderr).into()
24    }
25
26    pub fn success(&self) -> bool {
27        self.code == Some(0)
28    }
29}
30
31#[derive(Default)]
32struct Handler {}
33
34impl thrussh::client::Handler for Handler {
35    type Error = ClientError;
36    type FutureBool = future::Ready<Result<(Self, bool), Self::Error>>;
37    type FutureUnit = future::Ready<Result<(Self, thrussh::client::Session), Self::Error>>;
38
39    fn finished_bool(self, b: bool) -> Self::FutureBool {
40        future::ready(Ok((self, b)))
41    }
42
43    fn finished(self, session: thrussh::client::Session) -> Self::FutureUnit {
44        future::ready(Ok((self, session)))
45    }
46
47    #[allow(unused_variables)]
48    fn check_server_key(self, server_public_key: &key::PublicKey) -> Self::FutureBool {
49        self.finished_bool(true)
50    }
51}