From 07c4d0c4686ad736b623cb3e6a02e3ad4d04d98b Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Thu, 14 Dec 2023 10:24:54 -0800 Subject: [PATCH 1/4] async-signature: move to `AFIT` `AFIT` is expected in the upcoming rust-1.75 release (scheduled for 2023/12/28). `#[allow(async_fn_in_trait)]` is required until a solution to RPITIT is merged in rust. This put responsability on the implementor of `async_signature::AsyncSigner` to make sure their future is `Send`able. see https://github.com/rust-lang/rust/pull/115822#issuecomment-1731149475 for more context. --- async-signature/Cargo.toml | 2 +- async-signature/src/lib.rs | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/async-signature/Cargo.toml b/async-signature/Cargo.toml index 753f62944..d5bc4511c 100644 --- a/async-signature/Cargo.toml +++ b/async-signature/Cargo.toml @@ -10,7 +10,7 @@ readme = "README.md" keywords = ["crypto", "ecdsa", "ed25519", "signature", "signing"] categories = ["cryptography", "no-std"] edition = "2021" -rust-version = "1.60" +rust-version = "1.75" [dependencies] async-trait = "0.1.9" diff --git a/async-signature/src/lib.rs b/async-signature/src/lib.rs index 8c59952ca..6b88d34d7 100644 --- a/async-signature/src/lib.rs +++ b/async-signature/src/lib.rs @@ -17,13 +17,12 @@ pub use signature::{self, Error}; #[cfg(feature = "digest")] pub use signature::digest::{self, Digest}; -use async_trait::async_trait; /// Asynchronously sign the provided message bytestring using `Self` /// (e.g. client for a Cloud KMS or HSM), returning a digital signature. /// /// This trait is an async equivalent of the [`signature::Signer`] trait. -#[async_trait(?Send)] +#[allow(async_fn_in_trait)] pub trait AsyncSigner { /// Attempt to sign the given message, returning a digital signature on /// success, or an error if something went wrong. @@ -33,7 +32,6 @@ pub trait AsyncSigner { async fn sign_async(&self, msg: &[u8]) -> Result; } -#[async_trait(?Send)] impl AsyncSigner for T where S: 'static, @@ -48,7 +46,7 @@ where /// /// This trait is an async equivalent of the [`signature::DigestSigner`] trait. #[cfg(feature = "digest")] -#[async_trait(?Send)] +#[allow(async_fn_in_trait)] pub trait AsyncDigestSigner where D: Digest + 'static, @@ -60,7 +58,6 @@ where } #[cfg(feature = "digest")] -#[async_trait(?Send)] impl AsyncDigestSigner for T where D: Digest + 'static, From 8b8fac88350958105edad7b66deefe22939f8394 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Thu, 14 Dec 2023 10:30:12 -0800 Subject: [PATCH 2/4] async-signature: introduce an `AsyncRandomizedSigner` trait --- async-signature/Cargo.toml | 1 + async-signature/src/lib.rs | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/async-signature/Cargo.toml b/async-signature/Cargo.toml index d5bc4511c..7028483ce 100644 --- a/async-signature/Cargo.toml +++ b/async-signature/Cargo.toml @@ -18,6 +18,7 @@ signature = ">= 2.0, <2.3" [features] digest = ["signature/digest"] +rand_core = ["signature/rand_core"] [package.metadata.docs.rs] all-features = true diff --git a/async-signature/src/lib.rs b/async-signature/src/lib.rs index 6b88d34d7..1dcd2b199 100644 --- a/async-signature/src/lib.rs +++ b/async-signature/src/lib.rs @@ -17,6 +17,8 @@ pub use signature::{self, Error}; #[cfg(feature = "digest")] pub use signature::digest::{self, Digest}; +#[cfg(feature = "rand_core")] +use signature::rand_core::CryptoRngCore; /// Asynchronously sign the provided message bytestring using `Self` /// (e.g. client for a Cloud KMS or HSM), returning a digital signature. @@ -68,3 +70,41 @@ where self.try_sign_digest(digest) } } + +/// Sign the given message using the provided external randomness source. +#[cfg(feature = "rand_core")] +#[allow(async_fn_in_trait)] +pub trait AsyncRandomizedSigner { + /// Sign the given message and return a digital signature + async fn sign_with_rng_async(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> S { + self.try_sign_with_rng_async(rng, msg) + .await + .expect("signature operation failed") + } + + /// Attempt to sign the given message, returning a digital signature on + /// success, or an error if something went wrong. + /// + /// The main intended use case for signing errors is when communicating + /// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens. + async fn try_sign_with_rng_async( + &self, + rng: &mut impl CryptoRngCore, + msg: &[u8], + ) -> Result; +} + +#[cfg(feature = "rand_core")] +impl AsyncRandomizedSigner for T +where + S: 'static, + T: signature::RandomizedSigner, +{ + async fn try_sign_with_rng_async( + &self, + rng: &mut impl CryptoRngCore, + msg: &[u8], + ) -> Result { + self.try_sign_with_rng(rng, msg) + } +} From fc8e15b3f365284abe790cb8560f72b5dad480c7 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Thu, 14 Dec 2023 11:03:08 -0800 Subject: [PATCH 3/4] WIP: async-signature: bring rustc beta for AFIT support --- .github/workflows/async-signature.yml | 3 +-- .github/workflows/workspace.yml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/async-signature.yml b/.github/workflows/async-signature.yml index 41aba9707..60bfab329 100644 --- a/.github/workflows/async-signature.yml +++ b/.github/workflows/async-signature.yml @@ -23,8 +23,7 @@ jobs: strategy: matrix: rust: - - 1.60.0 # MSRV - - stable + - beta steps: - uses: actions/checkout@v4 - uses: RustCrypto/actions/cargo-cache@master diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index d0840aed0..5293f4117 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -36,6 +36,6 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: stable + toolchain: beta components: rustfmt - run: cargo fmt --all -- --check From 8017603e8ecd6fe9be8e1681a68d01e97115d6d8 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Fri, 29 Dec 2023 10:55:36 -0700 Subject: [PATCH 4/4] MSRV 1.75 --- .github/workflows/async-signature.yml | 3 ++- .github/workflows/workspace.yml | 2 +- Cargo.lock | 12 ------------ async-signature/Cargo.toml | 1 - async-signature/README.md | 4 ++-- 5 files changed, 5 insertions(+), 17 deletions(-) diff --git a/.github/workflows/async-signature.yml b/.github/workflows/async-signature.yml index 60bfab329..589fc27f9 100644 --- a/.github/workflows/async-signature.yml +++ b/.github/workflows/async-signature.yml @@ -23,7 +23,8 @@ jobs: strategy: matrix: rust: - - beta + - 1.75.0 # MSRV + - stable steps: - uses: actions/checkout@v4 - uses: RustCrypto/actions/cargo-cache@master diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index 5293f4117..d0840aed0 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -36,6 +36,6 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: beta + toolchain: stable components: rustfmt - run: cargo fmt --all -- --check diff --git a/Cargo.lock b/Cargo.lock index 4456a4a23..e573a449d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,21 +58,9 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" name = "async-signature" version = "0.4.0" dependencies = [ - "async-trait", "signature 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "async-trait" -version = "0.1.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdf6721fb0140e4f897002dd086c06f6c27775df19cfe1fccb21181a48fd2c98" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "base16ct" version = "0.1.1" diff --git a/async-signature/Cargo.toml b/async-signature/Cargo.toml index 7028483ce..14fc45ebb 100644 --- a/async-signature/Cargo.toml +++ b/async-signature/Cargo.toml @@ -13,7 +13,6 @@ edition = "2021" rust-version = "1.75" [dependencies] -async-trait = "0.1.9" signature = ">= 2.0, <2.3" [features] diff --git a/async-signature/README.md b/async-signature/README.md index 55b6e64c1..1a5b5be9b 100644 --- a/async-signature/README.md +++ b/async-signature/README.md @@ -9,7 +9,7 @@ ## Minimum Supported Rust Version -Rust **1.60** or higher. +Rust **1.75** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -36,7 +36,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/async-signature/badge.svg [docs-link]: https://docs.rs/async-signature/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.60+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.75+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260048-signatures [build-image]: https://github.com/RustCrypto/traits/workflows/async-signature/badge.svg?branch=master&event=push