From 52ab79028bf39ae1b5b2122833a3ee32dfcce476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Wed, 13 Nov 2024 20:06:37 +0300 Subject: [PATCH] Migrate to `core::error::Error` --- .github/workflows/async-signature.yml | 2 +- .github/workflows/password-hash.yml | 4 +-- .github/workflows/signature.yml | 4 +-- async-signature/Cargo.toml | 2 +- async-signature/README.md | 4 +-- digest/src/lib.rs | 6 ++-- digest/src/mac.rs | 3 +- password-hash/Cargo.toml | 3 +- password-hash/README.md | 4 +-- password-hash/src/errors.rs | 11 +++--- password-hash/src/lib.rs | 2 -- signature/Cargo.toml | 3 +- signature/README.md | 4 +-- signature/src/error.rs | 49 +++++++++++++++------------ signature/src/lib.rs | 2 -- universal-hash/Cargo.toml | 3 -- universal-hash/src/lib.rs | 6 +--- 17 files changed, 51 insertions(+), 61 deletions(-) diff --git a/.github/workflows/async-signature.yml b/.github/workflows/async-signature.yml index dbef8e7b..1846df7c 100644 --- a/.github/workflows/async-signature.yml +++ b/.github/workflows/async-signature.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.75.0 # MSRV + - 1.81.0 # MSRV - stable target: - thumbv7em-none-eabi diff --git a/.github/workflows/password-hash.yml b/.github/workflows/password-hash.yml index 2a732455..0b4754a1 100644 --- a/.github/workflows/password-hash.yml +++ b/.github/workflows/password-hash.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.60.0 # MSRV + - 1.81.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -57,7 +57,7 @@ jobs: strategy: matrix: rust: - - 1.60.0 # MSRV + - 1.81.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/signature.yml b/.github/workflows/signature.yml index c2dfd14a..a54fe047 100644 --- a/.github/workflows/signature.yml +++ b/.github/workflows/signature.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: rust: - - 1.72.0 # MSRV + - 1.81.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -68,7 +68,7 @@ jobs: strategy: matrix: rust: - - 1.72.0 # MSRV + - 1.81.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/async-signature/Cargo.toml b/async-signature/Cargo.toml index 50ac9a70..0fe015a4 100644 --- a/async-signature/Cargo.toml +++ b/async-signature/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" keywords = ["crypto", "ecdsa", "ed25519", "signature", "signing"] categories = ["cryptography", "no-std"] edition = "2021" -rust-version = "1.75" +rust-version = "1.81" [dependencies] signature = "=2.3.0-pre.4" diff --git a/async-signature/README.md b/async-signature/README.md index 1a5b5be9..83866137 100644 --- a/async-signature/README.md +++ b/async-signature/README.md @@ -9,7 +9,7 @@ ## Minimum Supported Rust Version -Rust **1.75** or higher. +Rust **1.81** 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.75+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.81+-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 diff --git a/digest/src/lib.rs b/digest/src/lib.rs index a9f5b7a4..a3e6fca8 100644 --- a/digest/src/lib.rs +++ b/digest/src/lib.rs @@ -284,8 +284,7 @@ impl fmt::Display for InvalidOutputSize { } } -#[cfg(feature = "std")] -impl std::error::Error for InvalidOutputSize {} +impl core::error::Error for InvalidOutputSize {} /// Buffer length is not equal to hash output size. #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)] @@ -297,8 +296,7 @@ impl fmt::Display for InvalidBufferSize { } } -#[cfg(feature = "std")] -impl std::error::Error for InvalidBufferSize {} +impl core::error::Error for InvalidBufferSize {} #[cfg(feature = "std")] mod hashwriter; diff --git a/digest/src/mac.rs b/digest/src/mac.rs index d3464863..395f86e0 100644 --- a/digest/src/mac.rs +++ b/digest/src/mac.rs @@ -278,5 +278,4 @@ impl fmt::Display for MacError { } } -#[cfg(feature = "std")] -impl std::error::Error for MacError {} +impl core::error::Error for MacError {} diff --git a/password-hash/Cargo.toml b/password-hash/Cargo.toml index 543a789f..ca1d81c4 100644 --- a/password-hash/Cargo.toml +++ b/password-hash/Cargo.toml @@ -15,7 +15,7 @@ repository = "https://github.com/RustCrypto/traits" categories = ["authentication", "cryptography", "no-std"] keywords = ["crypt", "mcf", "password", "pbkdf", "phc"] edition = "2021" -rust-version = "1.60" +rust-version = "1.81" [dependencies] base64ct = "1.6" @@ -27,7 +27,6 @@ rand_core = { version = "0.6.4", optional = true, default-features = false } [features] default = ["rand_core"] alloc = ["base64ct/alloc"] -std = ["alloc", "base64ct/std", "rand_core/std"] getrandom = ["rand_core/getrandom"] diff --git a/password-hash/README.md b/password-hash/README.md index dd376cd5..20dffcd5 100644 --- a/password-hash/README.md +++ b/password-hash/README.md @@ -29,7 +29,7 @@ this crate for interoperability: ## Minimum Supported Rust Version -Rust **1.60** or higher. +Rust **1.81** or higher. Minimum supported Rust version may be changed in the future, but it will be accompanied by a minor version bump. @@ -63,7 +63,7 @@ dual licensed as above, without any additional terms or conditions. [build-image]: https://github.com/RustCrypto/traits/workflows/password-hash/badge.svg?branch=master&event=push [build-link]: https://github.com/RustCrypto/traits/actions?query=workflow:password-hash [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.81+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260046-password-hashes diff --git a/password-hash/src/errors.rs b/password-hash/src/errors.rs index c48a28df..11efd67b 100644 --- a/password-hash/src/errors.rs +++ b/password-hash/src/errors.rs @@ -99,11 +99,11 @@ impl fmt::Display for Error { } } -#[cfg(feature = "std")] -impl std::error::Error for Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for Error { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { - Self::B64Encoding(err) => Some(err), + // TODO: restore after base64ct will migrate to core::error::Error + // Self::B64Encoding(err) => Some(err), Self::ParamValueInvalid(err) => Some(err), Self::SaltInvalid(err) => Some(err), _ => None, @@ -167,5 +167,4 @@ impl fmt::Display for InvalidValue { } } -#[cfg(feature = "std")] -impl std::error::Error for InvalidValue {} +impl core::error::Error for InvalidValue {} diff --git a/password-hash/src/lib.rs b/password-hash/src/lib.rs index 8993cfa4..7e3f283f 100644 --- a/password-hash/src/lib.rs +++ b/password-hash/src/lib.rs @@ -27,8 +27,6 @@ #[cfg(feature = "alloc")] extern crate alloc; -#[cfg(feature = "std")] -extern crate std; #[cfg(feature = "rand_core")] pub use rand_core; diff --git a/signature/Cargo.toml b/signature/Cargo.toml index 9b2540b5..921f0756 100644 --- a/signature/Cargo.toml +++ b/signature/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" keywords = ["crypto", "ecdsa", "ed25519", "signature", "signing"] categories = ["cryptography", "no-std"] edition = "2021" -rust-version = "1.72" +rust-version = "1.81" [dependencies] derive = { package = "signature_derive", version = "2", optional = true, path = "../signature_derive" } @@ -24,6 +24,7 @@ sha2 = { version = "=0.11.0-pre.4", default-features = false } [features] alloc = [] +# TODO: remove this feature in the next breaking release std = ["alloc", "rand_core?/std"] [package.metadata.docs.rs] diff --git a/signature/README.md b/signature/README.md index ce11d14d..1da58187 100644 --- a/signature/README.md +++ b/signature/README.md @@ -17,7 +17,7 @@ the [RustCrypto] organization, as well as [`ed25519-dalek`]. ## Minimum Supported Rust Version -Rust **1.72** or higher. +Rust **1.81** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -56,7 +56,7 @@ dual licensed as above, without any additional terms or conditions. [build-image]: https://github.com/RustCrypto/traits/actions/workflows/signature.yml/badge.svg [build-link]: https://github.com/RustCrypto/traits/actions/workflows/signature.yml [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.72+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.81+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260048-signatures diff --git a/signature/src/error.rs b/signature/src/error.rs index 7d716a1d..dc30176c 100644 --- a/signature/src/error.rs +++ b/signature/src/error.rs @@ -2,8 +2,8 @@ use core::fmt::{self, Debug, Display}; -#[cfg(feature = "std")] -use std::boxed::Box; +#[cfg(feature = "alloc")] +use alloc::boxed::Box; /// Result type. /// @@ -16,17 +16,16 @@ pub type Result = core::result::Result; /// could potentially be used recover signing private keys or forge signatures /// (e.g. [BB'06]). /// -/// When the `std` feature is enabled, it impls [`std::error::Error`] and -/// supports an optional [`std::error::Error::source`], which can be used by -/// things like remote signers (e.g. HSM, KMS) to report I/O or auth errors. +/// When the `alloc` feature is enabled, it supports an optional [`core::error::Error::source`], +/// which can be used by things like remote signers (e.g. HSM, KMS) to report I/O or auth errors. /// /// [BB'06]: https://en.wikipedia.org/wiki/Daniel_Bleichenbacher #[derive(Default)] #[non_exhaustive] pub struct Error { /// Source of the error (if applicable). - #[cfg(feature = "std")] - source: Option>, + #[cfg(feature = "alloc")] + source: Option>, } impl Error { @@ -41,9 +40,9 @@ impl Error { /// errors e.g. signature parsing or verification errors. The intended use /// cases are for propagating errors related to external signers, e.g. /// communication/authentication errors with HSMs, KMS, etc. - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] pub fn from_source( - source: impl Into>, + source: impl Into>, ) -> Self { Self { source: Some(source.into()), @@ -52,12 +51,12 @@ impl Error { } impl Debug for Error { - #[cfg(not(feature = "std"))] + #[cfg(not(feature = "alloc"))] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("signature::Error {}") } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("signature::Error { source: ")?; @@ -77,31 +76,37 @@ impl Display for Error { } } -#[cfg(feature = "std")] -impl From> for Error { - fn from(source: Box) -> Error { +#[cfg(feature = "alloc")] +impl From> for Error { + fn from(source: Box) -> Error { Self::from_source(source) } } #[cfg(feature = "rand_core")] impl From for Error { - #[cfg(not(feature = "std"))] + #[cfg(not(feature = "alloc"))] fn from(_source: rand_core::Error) -> Error { Error::new() } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn from(source: rand_core::Error) -> Error { Error::from_source(source) } } -#[cfg(feature = "std")] -impl std::error::Error for Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - self.source - .as_ref() - .map(|source| source.as_ref() as &(dyn std::error::Error + 'static)) +impl core::error::Error for Error { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { + #[cfg(not(feature = "alloc"))] + { + None + } + #[cfg(feature = "alloc")] + { + self.source + .as_ref() + .map(|source| source.as_ref() as &(dyn core::error::Error + 'static)) + } } } diff --git a/signature/src/lib.rs b/signature/src/lib.rs index 902499fe..a3281f76 100644 --- a/signature/src/lib.rs +++ b/signature/src/lib.rs @@ -130,8 +130,6 @@ #[cfg(feature = "alloc")] extern crate alloc; -#[cfg(feature = "std")] -extern crate std; pub mod hazmat; diff --git a/universal-hash/Cargo.toml b/universal-hash/Cargo.toml index 2b004257..9068fa16 100644 --- a/universal-hash/Cargo.toml +++ b/universal-hash/Cargo.toml @@ -16,9 +16,6 @@ categories = ["cryptography", "no-std"] crypto-common = "0.2.0-rc.0" subtle = { version = "2.4", default-features = false } -[features] -std = [] - [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] diff --git a/universal-hash/src/lib.rs b/universal-hash/src/lib.rs index d6d43aff..06e75e65 100644 --- a/universal-hash/src/lib.rs +++ b/universal-hash/src/lib.rs @@ -8,9 +8,6 @@ #![forbid(unsafe_code)] #![warn(missing_docs, rust_2018_idioms, missing_debug_implementations)] -#[cfg(feature = "std")] -extern crate std; - pub use crypto_common::{ self, array, typenum::{self, consts}, @@ -152,5 +149,4 @@ impl core::fmt::Display for Error { } } -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {}