Skip to content

Commit f5266b8

Browse files
authored
Migrate to core::error::Error (#1711)
1 parent 70d3103 commit f5266b8

File tree

17 files changed

+51
-61
lines changed

17 files changed

+51
-61
lines changed

.github/workflows/async-signature.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
strategy:
2424
matrix:
2525
rust:
26-
- 1.75.0 # MSRV
26+
- 1.81.0 # MSRV
2727
- stable
2828
target:
2929
- thumbv7em-none-eabi

.github/workflows/password-hash.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
matrix:
2424
rust:
25-
- 1.60.0 # MSRV
25+
- 1.81.0 # MSRV
2626
- stable
2727
target:
2828
- thumbv7em-none-eabi
@@ -57,7 +57,7 @@ jobs:
5757
strategy:
5858
matrix:
5959
rust:
60-
- 1.60.0 # MSRV
60+
- 1.81.0 # MSRV
6161
- stable
6262
steps:
6363
- uses: actions/checkout@v4

.github/workflows/signature.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
matrix:
2626
rust:
27-
- 1.72.0 # MSRV
27+
- 1.81.0 # MSRV
2828
- stable
2929
target:
3030
- thumbv7em-none-eabi
@@ -68,7 +68,7 @@ jobs:
6868
strategy:
6969
matrix:
7070
rust:
71-
- 1.72.0 # MSRV
71+
- 1.81.0 # MSRV
7272
- stable
7373
steps:
7474
- uses: actions/checkout@v4

async-signature/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readme = "README.md"
1111
keywords = ["crypto", "ecdsa", "ed25519", "signature", "signing"]
1212
categories = ["cryptography", "no-std"]
1313
edition = "2021"
14-
rust-version = "1.75"
14+
rust-version = "1.81"
1515

1616
[dependencies]
1717
signature = "=2.3.0-pre.4"

async-signature/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
## Minimum Supported Rust Version
1111

12-
Rust **1.75** or higher.
12+
Rust **1.81** or higher.
1313

1414
Minimum supported Rust version can be changed in the future, but it will be
1515
done with a minor version bump.
@@ -36,7 +36,7 @@ dual licensed as above, without any additional terms or conditions.
3636
[docs-image]: https://docs.rs/async-signature/badge.svg
3737
[docs-link]: https://docs.rs/async-signature/
3838
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
39-
[rustc-image]: https://img.shields.io/badge/rustc-1.75+-blue.svg
39+
[rustc-image]: https://img.shields.io/badge/rustc-1.81+-blue.svg
4040
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
4141
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260048-signatures
4242
[build-image]: https://github.com/RustCrypto/traits/workflows/async-signature/badge.svg?branch=master&event=push

digest/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,7 @@ impl fmt::Display for InvalidOutputSize {
284284
}
285285
}
286286

287-
#[cfg(feature = "std")]
288-
impl std::error::Error for InvalidOutputSize {}
287+
impl core::error::Error for InvalidOutputSize {}
289288

290289
/// Buffer length is not equal to hash output size.
291290
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
@@ -297,8 +296,7 @@ impl fmt::Display for InvalidBufferSize {
297296
}
298297
}
299298

300-
#[cfg(feature = "std")]
301-
impl std::error::Error for InvalidBufferSize {}
299+
impl core::error::Error for InvalidBufferSize {}
302300

303301
#[cfg(feature = "std")]
304302
mod hashwriter;

digest/src/mac.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,4 @@ impl fmt::Display for MacError {
278278
}
279279
}
280280

281-
#[cfg(feature = "std")]
282-
impl std::error::Error for MacError {}
281+
impl core::error::Error for MacError {}

password-hash/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repository = "https://github.com/RustCrypto/traits"
1515
categories = ["authentication", "cryptography", "no-std"]
1616
keywords = ["crypt", "mcf", "password", "pbkdf", "phc"]
1717
edition = "2021"
18-
rust-version = "1.60"
18+
rust-version = "1.81"
1919

2020
[dependencies]
2121
base64ct = "1.6"
@@ -27,7 +27,6 @@ rand_core = { version = "0.6.4", optional = true, default-features = false }
2727
[features]
2828
default = ["rand_core"]
2929
alloc = ["base64ct/alloc"]
30-
std = ["alloc", "base64ct/std", "rand_core/std"]
3130

3231
getrandom = ["rand_core/getrandom"]
3332

password-hash/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ this crate for interoperability:
2929

3030
## Minimum Supported Rust Version
3131

32-
Rust **1.60** or higher.
32+
Rust **1.81** or higher.
3333

3434
Minimum supported Rust version may be changed in the future, but it will be
3535
accompanied by a minor version bump.
@@ -63,7 +63,7 @@ dual licensed as above, without any additional terms or conditions.
6363
[build-image]: https://github.com/RustCrypto/traits/workflows/password-hash/badge.svg?branch=master&event=push
6464
[build-link]: https://github.com/RustCrypto/traits/actions?query=workflow:password-hash
6565
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
66-
[rustc-image]: https://img.shields.io/badge/rustc-1.60+-blue.svg
66+
[rustc-image]: https://img.shields.io/badge/rustc-1.81+-blue.svg
6767
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
6868
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260046-password-hashes
6969

password-hash/src/errors.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ impl fmt::Display for Error {
9999
}
100100
}
101101

102-
#[cfg(feature = "std")]
103-
impl std::error::Error for Error {
104-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
102+
impl core::error::Error for Error {
103+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
105104
match self {
106-
Self::B64Encoding(err) => Some(err),
105+
// TODO: restore after base64ct will migrate to core::error::Error
106+
// Self::B64Encoding(err) => Some(err),
107107
Self::ParamValueInvalid(err) => Some(err),
108108
Self::SaltInvalid(err) => Some(err),
109109
_ => None,
@@ -167,5 +167,4 @@ impl fmt::Display for InvalidValue {
167167
}
168168
}
169169

170-
#[cfg(feature = "std")]
171-
impl std::error::Error for InvalidValue {}
170+
impl core::error::Error for InvalidValue {}

password-hash/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
2828
#[cfg(feature = "alloc")]
2929
extern crate alloc;
30-
#[cfg(feature = "std")]
31-
extern crate std;
3230

3331
#[cfg(feature = "rand_core")]
3432
pub use rand_core;

signature/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readme = "README.md"
1111
keywords = ["crypto", "ecdsa", "ed25519", "signature", "signing"]
1212
categories = ["cryptography", "no-std"]
1313
edition = "2021"
14-
rust-version = "1.72"
14+
rust-version = "1.81"
1515

1616
[dependencies]
1717
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 }
2424

2525
[features]
2626
alloc = []
27+
# TODO: remove this feature in the next breaking release
2728
std = ["alloc", "rand_core?/std"]
2829

2930
[package.metadata.docs.rs]

signature/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ the [RustCrypto] organization, as well as [`ed25519-dalek`].
1717

1818
## Minimum Supported Rust Version
1919

20-
Rust **1.72** or higher.
20+
Rust **1.81** or higher.
2121

2222
Minimum supported Rust version can be changed in the future, but it will be
2323
done with a minor version bump.
@@ -56,7 +56,7 @@ dual licensed as above, without any additional terms or conditions.
5656
[build-image]: https://github.com/RustCrypto/traits/actions/workflows/signature.yml/badge.svg
5757
[build-link]: https://github.com/RustCrypto/traits/actions/workflows/signature.yml
5858
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
59-
[rustc-image]: https://img.shields.io/badge/rustc-1.72+-blue.svg
59+
[rustc-image]: https://img.shields.io/badge/rustc-1.81+-blue.svg
6060
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
6161
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260048-signatures
6262

signature/src/error.rs

+27-22
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use core::fmt::{self, Debug, Display};
44

5-
#[cfg(feature = "std")]
6-
use std::boxed::Box;
5+
#[cfg(feature = "alloc")]
6+
use alloc::boxed::Box;
77

88
/// Result type.
99
///
@@ -16,17 +16,16 @@ pub type Result<T> = core::result::Result<T, Error>;
1616
/// could potentially be used recover signing private keys or forge signatures
1717
/// (e.g. [BB'06]).
1818
///
19-
/// When the `std` feature is enabled, it impls [`std::error::Error`] and
20-
/// supports an optional [`std::error::Error::source`], which can be used by
21-
/// things like remote signers (e.g. HSM, KMS) to report I/O or auth errors.
19+
/// When the `alloc` feature is enabled, it supports an optional [`core::error::Error::source`],
20+
/// which can be used by things like remote signers (e.g. HSM, KMS) to report I/O or auth errors.
2221
///
2322
/// [BB'06]: https://en.wikipedia.org/wiki/Daniel_Bleichenbacher
2423
#[derive(Default)]
2524
#[non_exhaustive]
2625
pub struct Error {
2726
/// Source of the error (if applicable).
28-
#[cfg(feature = "std")]
29-
source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
27+
#[cfg(feature = "alloc")]
28+
source: Option<Box<dyn core::error::Error + Send + Sync + 'static>>,
3029
}
3130

3231
impl Error {
@@ -41,9 +40,9 @@ impl Error {
4140
/// errors e.g. signature parsing or verification errors. The intended use
4241
/// cases are for propagating errors related to external signers, e.g.
4342
/// communication/authentication errors with HSMs, KMS, etc.
44-
#[cfg(feature = "std")]
43+
#[cfg(feature = "alloc")]
4544
pub fn from_source(
46-
source: impl Into<Box<dyn std::error::Error + Send + Sync + 'static>>,
45+
source: impl Into<Box<dyn core::error::Error + Send + Sync + 'static>>,
4746
) -> Self {
4847
Self {
4948
source: Some(source.into()),
@@ -52,12 +51,12 @@ impl Error {
5251
}
5352

5453
impl Debug for Error {
55-
#[cfg(not(feature = "std"))]
54+
#[cfg(not(feature = "alloc"))]
5655
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5756
f.write_str("signature::Error {}")
5857
}
5958

60-
#[cfg(feature = "std")]
59+
#[cfg(feature = "alloc")]
6160
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6261
f.write_str("signature::Error { source: ")?;
6362

@@ -77,31 +76,37 @@ impl Display for Error {
7776
}
7877
}
7978

80-
#[cfg(feature = "std")]
81-
impl From<Box<dyn std::error::Error + Send + Sync + 'static>> for Error {
82-
fn from(source: Box<dyn std::error::Error + Send + Sync + 'static>) -> Error {
79+
#[cfg(feature = "alloc")]
80+
impl From<Box<dyn core::error::Error + Send + Sync + 'static>> for Error {
81+
fn from(source: Box<dyn core::error::Error + Send + Sync + 'static>) -> Error {
8382
Self::from_source(source)
8483
}
8584
}
8685

8786
#[cfg(feature = "rand_core")]
8887
impl From<rand_core::Error> for Error {
89-
#[cfg(not(feature = "std"))]
88+
#[cfg(not(feature = "alloc"))]
9089
fn from(_source: rand_core::Error) -> Error {
9190
Error::new()
9291
}
9392

94-
#[cfg(feature = "std")]
93+
#[cfg(feature = "alloc")]
9594
fn from(source: rand_core::Error) -> Error {
9695
Error::from_source(source)
9796
}
9897
}
9998

100-
#[cfg(feature = "std")]
101-
impl std::error::Error for Error {
102-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
103-
self.source
104-
.as_ref()
105-
.map(|source| source.as_ref() as &(dyn std::error::Error + 'static))
99+
impl core::error::Error for Error {
100+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
101+
#[cfg(not(feature = "alloc"))]
102+
{
103+
None
104+
}
105+
#[cfg(feature = "alloc")]
106+
{
107+
self.source
108+
.as_ref()
109+
.map(|source| source.as_ref() as &(dyn core::error::Error + 'static))
110+
}
106111
}
107112
}

signature/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@
130130
131131
#[cfg(feature = "alloc")]
132132
extern crate alloc;
133-
#[cfg(feature = "std")]
134-
extern crate std;
135133

136134
pub mod hazmat;
137135

universal-hash/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ categories = ["cryptography", "no-std"]
1616
crypto-common = "0.2.0-rc.0"
1717
subtle = { version = "2.4", default-features = false }
1818

19-
[features]
20-
std = []
21-
2219
[package.metadata.docs.rs]
2320
all-features = true
2421
rustdoc-args = ["--cfg", "docsrs"]

universal-hash/src/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
#![forbid(unsafe_code)]
99
#![warn(missing_docs, rust_2018_idioms, missing_debug_implementations)]
1010

11-
#[cfg(feature = "std")]
12-
extern crate std;
13-
1411
pub use crypto_common::{
1512
self, array,
1613
typenum::{self, consts},
@@ -152,5 +149,4 @@ impl core::fmt::Display for Error {
152149
}
153150
}
154151

155-
#[cfg(feature = "std")]
156-
impl std::error::Error for Error {}
152+
impl core::error::Error for Error {}

0 commit comments

Comments
 (0)