Skip to content

Commit

Permalink
Leverage core::error::Error; MSRV 1.81
Browse files Browse the repository at this point in the history
Now that `core::error::Error` is stable in 1.81, leverages it to make
the `Error` impl always available.

Since `ssh-cipher` has no other dependencies on `std`, removes the `std`
feature from this crate entirely.
  • Loading branch information
tarcieri committed Oct 15, 2024
1 parent b7dfc0b commit c25e95b
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ssh-cipher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
matrix:
rust:
- 1.72.0 # MSRV
- 1.81.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand All @@ -49,7 +49,7 @@ jobs:
strategy:
matrix:
rust:
- 1.72.0 # MSRV
- 1.81.0 # MSRV
- stable
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ssh-encoding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
matrix:
rust:
- 1.71.0 # MSRV
- 1.81.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand All @@ -47,7 +47,7 @@ jobs:
strategy:
matrix:
rust:
- 1.71.0 # MSRV
- 1.81.0 # MSRV
- stable
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ssh-key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
strategy:
matrix:
rust:
- 1.73.0 # MSRV
- 1.81.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand All @@ -80,7 +80,7 @@ jobs:
strategy:
matrix:
rust:
- 1.73.0 # MSRV
- 1.81.0 # MSRV
- stable
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ssh-protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
matrix:
rust:
- 1.73.0 # MSRV
- 1.81.0 # MSRV
- stable
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.80.0
toolchain: 1.81.0
components: clippy
- run: cargo clippy --all-features

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions ssh-cipher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ categories = ["cryptography", "no-std"]
keywords = ["crypto", "encryption", "openssh", "ssh"]
readme = "README.md"
edition = "2021"
rust-version = "1.72"
rust-version = "1.81"

[dependencies]
cipher = "=0.5.0-pre.6"
Expand All @@ -38,8 +38,6 @@ zeroize = { version = "1", optional = true, default-features = false }
hex-literal = "0.4"

[features]
std = []

aes-cbc = ["dep:aes", "dep:cbc"]
aes-ctr = ["dep:aes", "dep:ctr"]
aes-gcm = ["dep:aead", "dep:aes", "dep:aes-gcm"]
Expand Down
4 changes: 2 additions & 2 deletions ssh-cipher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Built on the pure Rust cryptography implementations maintained by the

## Minimum Supported Rust Version

This crate requires **Rust 1.60** at a minimum.
This crate requires **Rust 1.81** at a minimum.

We may change the MSRV in the future, but it will be accompanied by a minor
version bump.
Expand All @@ -48,7 +48,7 @@ dual licensed as above, without any additional terms or conditions.
[docs-image]: https://docs.rs/ssh-cipher/badge.svg
[docs-link]: https://docs.rs/ssh-cipher/
[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/346919-SSH
[build-image]: https://github.com/RustCrypto/SSH/actions/workflows/ssh-cipher.yml/badge.svg
Expand Down
3 changes: 1 addition & 2 deletions ssh-cipher/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,4 @@ impl fmt::Display for Error {
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}
impl core::error::Error for Error {}
3 changes: 0 additions & 3 deletions ssh-cipher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
unused_qualifications
)]

#[cfg(feature = "std")]
extern crate std;

mod error;

#[cfg(feature = "chacha20poly1305")]
Expand Down
5 changes: 2 additions & 3 deletions ssh-encoding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ categories = ["authentication", "cryptography", "encoding", "no-std", "parser-im
keywords = ["crypto", "certificate", "key", "openssh", "ssh"]
readme = "README.md"
edition = "2021"
rust-version = "1.71"
rust-version = "1.81"

[dependencies]
base64ct = { version = "1.4", optional = true }
bytes = { version = "1", optional = true, default-features = false }
digest = { version = "=0.11.0-pre.9", optional = true, default-features = false }
pem-rfc7468 = { version = "1.0.0-rc.1", optional = true }
pem-rfc7468 = { version = "1.0.0-rc.2", optional = true }

[dev-dependencies]
hex-literal = "0.4.1"

[features]
alloc = ["base64ct?/alloc", "pem-rfc7468?/alloc"]
std = ["alloc", "base64ct?/std", "digest?/std", "pem-rfc7468?/std"]

base64 = ["dep:base64ct"]
bytes = ["alloc", "dep:bytes"]
Expand Down
4 changes: 2 additions & 2 deletions ssh-encoding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ in [RFC4251].

## Minimum Supported Rust Version

This crate requires **Rust 1.71** at a minimum.
This crate requires **Rust 1.81** at a minimum.

We may change the MSRV in the future, but it will be accompanied by a minor
version bump.
Expand All @@ -43,7 +43,7 @@ dual licensed as above, without any additional terms or conditions.
[docs-image]: https://docs.rs/ssh-encoding/badge.svg
[docs-link]: https://docs.rs/ssh-encoding/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.71+-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/346919-SSH
[build-image]: https://github.com/RustCrypto/SSH/actions/workflows/ssh-encoding.yml/badge.svg
Expand Down
26 changes: 13 additions & 13 deletions ssh-encoding/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ pub enum Error {
},
}

impl core::error::Error for Error {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
// TODO(tarcieri): re-add support when `base64ct` uses `core::error`
//#[cfg(feature = "base64")]
//Self::Base64(err) => Some(err),
#[cfg(feature = "pem")]
Self::Pem(err) => Some(err),
_ => None,
}
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down Expand Up @@ -101,16 +114,3 @@ impl From<pem_rfc7468::Error> for Error {
Error::Pem(err)
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
#[cfg(feature = "base64")]
Self::Base64(err) => Some(err),
#[cfg(feature = "pem")]
Self::Pem(err) => Some(err),
_ => None,
}
}
}
5 changes: 2 additions & 3 deletions ssh-encoding/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ impl LabelError {
}
}

impl core::error::Error for LabelError {}

impl fmt::Display for LabelError {
#[cfg(not(feature = "alloc"))]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand All @@ -77,6 +79,3 @@ impl fmt::Display for LabelError {
write!(f, "invalid label: '{}'", self.label)
}
}

#[cfg(feature = "std")]
impl std::error::Error for LabelError {}
2 changes: 0 additions & 2 deletions ssh-encoding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#[cfg(feature = "alloc")]
#[macro_use]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

mod checked;
mod decode;
Expand Down
3 changes: 1 addition & 2 deletions ssh-key/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = ["authentication", "cryptography", "encoding", "no-std", "parser-im
keywords = ["crypto", "certificate", "openssh", "ssh", "sshsig"]
readme = "README.md"
edition = "2021"
rust-version = "1.73"
rust-version = "1.81"

[dependencies]
cipher = { package = "ssh-cipher", version = "=0.3.0-pre.2", features = ["zeroize"], path = "../ssh-cipher" }
Expand Down Expand Up @@ -53,7 +53,6 @@ alloc = [
]
std = [
"alloc",
"encoding/std",
"p256?/std",
"p384?/std",
"p521?/std",
Expand Down
4 changes: 2 additions & 2 deletions ssh-key/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ functionality for a particular SSH key algorithm.

## Minimum Supported Rust Version

This crate requires **Rust 1.73** at a minimum.
This crate requires **Rust 1.81** at a minimum.

We may change the MSRV in the future, but it will be accompanied by a minor
version bump.
Expand All @@ -113,7 +113,7 @@ dual licensed as above, without any additional terms or conditions.
[docs-image]: https://docs.rs/ssh-key/badge.svg
[docs-link]: https://docs.rs/ssh-key/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.73+-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/346919-SSH
[build-image]: https://github.com/RustCrypto/SSH/actions/workflows/ssh-key.yml/badge.svg
Expand Down
27 changes: 14 additions & 13 deletions ssh-key/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ impl fmt::Display for Error {
}
}

impl core::error::Error for Error {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
#[cfg(feature = "ecdsa")]
Self::Ecdsa(err) => Some(err),
Self::Encoding(err) => Some(err),
_ => None,
}
}
}

impl From<cipher::Error> for Error {
fn from(_: cipher::Error) -> Error {
Error::Crypto
Expand Down Expand Up @@ -157,6 +168,7 @@ impl From<encoding::pem::Error> for Error {
}
}

// TODO(tarcieri): avoid special casing this when `signature` supports `core::error::Error`
#[cfg(not(feature = "std"))]
impl From<signature::Error> for Error {
fn from(_: signature::Error) -> Error {
Expand All @@ -167,14 +179,15 @@ impl From<signature::Error> for Error {
#[cfg(feature = "std")]
impl From<signature::Error> for Error {
fn from(err: signature::Error) -> Error {
use std::error::Error as _;
use core::error::Error as _;

err.source()
.and_then(|source| source.downcast_ref().cloned())
.unwrap_or(Error::Crypto)
}
}

// TODO(tarcieri): avoid special casing this when `signature` supports `core::error::Error`
#[cfg(not(feature = "std"))]
impl From<Error> for signature::Error {
fn from(_: Error) -> signature::Error {
Expand Down Expand Up @@ -223,15 +236,3 @@ impl From<std::time::SystemTimeError> for Error {
Error::Time
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
#[cfg(feature = "ecdsa")]
Self::Ecdsa(err) => Some(err),
Self::Encoding(err) => Some(err),
_ => None,
}
}
}
4 changes: 2 additions & 2 deletions ssh-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ categories = ["authentication", "cryptography", "encoding", "no-std"]
keywords = ["crypto", "certificate", "openssh", "ssh", "sshsig"]
readme = "README.md"
edition = "2021"
rust-version = "1.73"
rust-version = "1.81"

[dependencies]
cipher = { package = "ssh-cipher", version = "=0.3.0-pre.2", default-features = false, path = "../ssh-cipher" }
Expand All @@ -23,7 +23,7 @@ key = { package = "ssh-key", version = "=0.7.0-pre.1", default-features = false,
[features]
default = ["std"]
alloc = ["encoding/alloc", "key/alloc"]
std = ["alloc", "encoding/std", "key/std"]
std = ["alloc", "key/std"]

[package.metadata.docs.rs]
all-features = true
Expand Down
4 changes: 2 additions & 2 deletions ssh-protocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ OpenSSH-specific extensions (WIP).

## Minimum Supported Rust Version

This crate requires **Rust 1.73** at a minimum.
This crate requires **Rust 1.81** at a minimum.

We may change the MSRV in the future, but it will be accompanied by a minor
version bump.
Expand All @@ -43,7 +43,7 @@ dual licensed as above, without any additional terms or conditions.
[docs-image]: https://docs.rs/ssh-protocol/badge.svg
[docs-link]: https://docs.rs/ssh-protocol/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.73+-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/346919-SSH
[build-image]: https://github.com/RustCrypto/SSH/actions/workflows/ssh-protocol.yml/badge.svg
Expand Down

0 comments on commit c25e95b

Please sign in to comment.