Skip to content

Commit

Permalink
Native async traits encore (#455) - note: MSRV: 1.75
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny authored Jan 27, 2025
1 parent 7109917 commit 3e04597
Show file tree
Hide file tree
Showing 23 changed files with 331 additions and 312 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,5 @@ jobs:

- name: Check with minimal dependency versions
run: |
rustup toolchain add 1.73.0
# minimal-versions cannot correctly resolve the ssh-key dep on Rust <1.73
cargo +1.73.0 minimal-versions check --all-features --no-dev-deps
rustup toolchain add 1.75.0
cargo +1.75.0 minimal-versions check --all-features --no-dev-deps
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ digest = "0.10"
delegate = "0.13"
env_logger = "0.6"
futures = "0.3"
home = "=0.5.5" # 0.5.6 changes MSRV
home = "0.5"
hmac = "0.12"
log = "0.4.11"
rand = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion cryptovec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache-2.0"
name = "russh-cryptovec"
repository = "https://github.com/warp-tech/russh"
version = "0.48.0"
rust-version = "1.60"
rust-version = "1.75"

[dependencies]
libc = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion pageant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache-2.0"
name = "pageant"
repository = "https://github.com/warp-tech/russh"
version = "0.0.2"
rust-version = "1.65"
rust-version = "1.75"

[dependencies]
futures.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion russh-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Apache-2.0"
name = "russh-config"
repository = "https://github.com/warp-tech/russh"
version = "0.48.0"
rust-version = "1.65"
rust-version = "1.75"

[dependencies]
home.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion russh-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "russh-util"
version = "0.48.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.75"
description = "Runtime abstraction utilities for russh."
documentation = "https://docs.rs/russh-util"
homepage = "https://github.com/warp-tech/russh"
Expand Down
13 changes: 11 additions & 2 deletions russh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ name = "russh"
readme = "../README.md"
repository = "https://github.com/warp-tech/russh"
version = "0.50.0-beta.11"
rust-version = "1.65"
rust-version = "1.75"

[features]
default = ["flate2"]
async-trait = ["dep:async-trait"]
legacy-ed25519-pkcs8-parser = ["yasna"]
# Danger: 3DES cipher is insecure.
des = ["dep:des"]

[dependencies]
aes-gcm = "0.10"
aes.workspace = true
async-trait.workspace = true
async-trait = { workspace = true, optional = true }
bitflags = "2.0"
block-padding = { version = "0.3", features = ["std"] }
byteorder.workspace = true
Expand Down Expand Up @@ -119,3 +120,11 @@ tempfile = "3.14.0"
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
russh-sftp = "2.0.5"
tokio.workspace = true

[[example]]
name = "sftp_server"
path = "examples/sftp_server.rs"
required-features = ["async-trait"]

[package.metadata.docs.rs]
all-features = true
2 changes: 0 additions & 2 deletions russh/examples/client_exec_interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::sync::Arc;
use std::time::Duration;

use anyhow::Result;
use async_trait::async_trait;
use clap::Parser;
use log::info;
use russh::keys::*;
Expand Down Expand Up @@ -65,7 +64,6 @@ struct Client {}
// More SSH event handlers
// can be defined in this trait
// In this example, we're only using Channel, so these aren't needed.
#[async_trait]
impl client::Handler for Client {
type Error = russh::Error;

Expand Down
2 changes: 0 additions & 2 deletions russh/examples/client_exec_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::sync::Arc;
use std::time::Duration;

use anyhow::Result;
use async_trait::async_trait;
use clap::Parser;
use log::info;
use russh::keys::*;
Expand Down Expand Up @@ -57,7 +56,6 @@ struct Client {}
// More SSH event handlers
// can be defined in this trait
// In this example, we're only using Channel, so these aren't needed.
#[async_trait]
impl client::Handler for Client {
type Error = russh::Error;

Expand Down
2 changes: 0 additions & 2 deletions russh/examples/echoserver.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;
use std::sync::Arc;

use async_trait::async_trait;
use rand_core::OsRng;
use russh::keys::{Certificate, *};
use russh::server::{Msg, Server as _, Session};
Expand Down Expand Up @@ -64,7 +63,6 @@ impl server::Server for Server {
}
}

#[async_trait]
impl server::Handler for Server {
type Error = russh::Error;

Expand Down
2 changes: 0 additions & 2 deletions russh/examples/ratatui_app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;
use std::sync::Arc;

use async_trait::async_trait;
use rand_core::OsRng;
use ratatui::backend::CrosstermBackend;
use ratatui::layout::Rect;
Expand Down Expand Up @@ -142,7 +141,6 @@ impl Server for AppServer {
}
}

#[async_trait]
impl Handler for AppServer {
type Error = anyhow::Error;

Expand Down
2 changes: 0 additions & 2 deletions russh/examples/ratatui_shared_app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;
use std::sync::Arc;

use async_trait::async_trait;
use rand_core::OsRng;
use ratatui::backend::CrosstermBackend;
use ratatui::layout::Rect;
Expand Down Expand Up @@ -144,7 +143,6 @@ impl Server for AppServer {
}
}

#[async_trait]
impl Handler for AppServer {
type Error = anyhow::Error;

Expand Down
2 changes: 0 additions & 2 deletions russh/examples/sftp_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::Arc;

use async_trait::async_trait;
use log::{error, info, LevelFilter};
use russh::keys::*;
use russh::*;
Expand All @@ -10,7 +9,6 @@ use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};

struct Client;

#[async_trait]
impl client::Handler for Client {
type Error = anyhow::Error;

Expand Down
4 changes: 1 addition & 3 deletions russh/examples/sftp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;

use async_trait::async_trait;
use log::{error, info, LevelFilter};
use rand_core::OsRng;
use russh::server::{Auth, Msg, Server as _, Session};
Expand Down Expand Up @@ -41,7 +40,6 @@ impl SshSession {
}
}

#[async_trait]
impl russh::server::Handler for SshSession {
type Error = anyhow::Error;

Expand Down Expand Up @@ -109,7 +107,7 @@ struct SftpSession {
root_dir_read_done: bool,
}

#[async_trait]
#[async_trait::async_trait]
impl russh_sftp::server::Handler for SftpSession {
type Error = StatusCode;

Expand Down
2 changes: 0 additions & 2 deletions russh/examples/test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;
use std::sync::{Arc, Mutex};

use async_trait::async_trait;
use log::debug;
use rand_core::OsRng;
use russh::keys::*;
Expand Down Expand Up @@ -47,7 +46,6 @@ impl server::Server for Server {
}
}

#[async_trait]
impl server::Handler for Server {
type Error = anyhow::Error;

Expand Down
23 changes: 13 additions & 10 deletions russh/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
// limitations under the License.
//

use std::future::Future;
use std::ops::Deref;
use std::str::FromStr;
use std::sync::Arc;

use async_trait::async_trait;
use ssh_key::{Certificate, HashAlg, PrivateKey};
use thiserror::Error;
use tokio::io::{AsyncRead, AsyncWrite};
Expand Down Expand Up @@ -147,16 +147,16 @@ impl AuthResult {
}
}

#[async_trait]
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
pub trait Signer: Sized {
type Error: From<crate::SendError>;

async fn auth_publickey_sign(
fn auth_publickey_sign(
&mut self,
key: &ssh_key::PublicKey,
hash_alg: Option<HashAlg>,
to_sign: CryptoVec,
) -> Result<CryptoVec, Self::Error>;
) -> impl Future<Output = Result<CryptoVec, Self::Error>> + Send;
}

#[derive(Debug, Error)]
Expand All @@ -167,21 +167,24 @@ pub enum AgentAuthError {
Key(#[from] crate::keys::Error),
}

#[async_trait]
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
impl<R: AsyncRead + AsyncWrite + Unpin + Send + 'static> Signer
for crate::keys::agent::client::AgentClient<R>
{
type Error = AgentAuthError;

async fn auth_publickey_sign(
#[allow(clippy::manual_async_fn)]
fn auth_publickey_sign(
&mut self,
key: &ssh_key::PublicKey,
hash_alg: Option<HashAlg>,
to_sign: CryptoVec,
) -> Result<CryptoVec, Self::Error> {
self.sign_request(key, hash_alg, to_sign)
.await
.map_err(Into::into)
) -> impl Future<Output = Result<CryptoVec, Self::Error>> {
async move {
self.sign_request(key, hash_alg, to_sign)
.await
.map_err(Into::into)
}
}
}

Expand Down
Loading

0 comments on commit 3e04597

Please sign in to comment.