From 5b260964cb60b5f2ab96e823ba6567b4ffaeba1d Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Mon, 6 Oct 2025 16:48:06 +0100 Subject: [PATCH] crypto: mark errors as `non_exhaustive` To improve crate version churn, mark the error types as `non_exhaustive`. This removes the need to change the version number of the crate when adding a new variant. Note that these errors are never matched on, so no other code is changed in dependent crates. --- crates/radicle-crypto/src/lib.rs | 3 +++ crates/radicle-crypto/src/ssh.rs | 4 ++++ crates/radicle-crypto/src/ssh/keystore.rs | 2 ++ 3 files changed, 9 insertions(+) diff --git a/crates/radicle-crypto/src/lib.rs b/crates/radicle-crypto/src/lib.rs index 5a60a4b1..0a7f3df5 100644 --- a/crates/radicle-crypto/src/lib.rs +++ b/crates/radicle-crypto/src/lib.rs @@ -28,6 +28,7 @@ pub type SharedSecret = [u8; 32]; /// Error returned if signing fails, eg. due to an HSM or KMS. #[derive(Debug, Clone, Error)] #[error(transparent)] +#[non_exhaustive] pub struct SignerError { #[from] source: Arc, @@ -93,6 +94,7 @@ impl fmt::Debug for Signature { } #[derive(Error, Debug)] +#[non_exhaustive] pub enum SignatureError { #[error("invalid multibase string: {0}")] Multibase(#[from] multibase::Error), @@ -273,6 +275,7 @@ impl Deref for SecretKey { } #[derive(Error, Debug)] +#[non_exhaustive] pub enum PublicKeyError { #[error("invalid length {0}")] InvalidLength(usize), diff --git a/crates/radicle-crypto/src/ssh.rs b/crates/radicle-crypto/src/ssh.rs index d1d045b5..45259ca5 100644 --- a/crates/radicle-crypto/src/ssh.rs +++ b/crates/radicle-crypto/src/ssh.rs @@ -16,6 +16,7 @@ use crate::PublicKey; pub use keystore::{Keystore, Passphrase}; #[derive(Debug, Error)] +#[non_exhaustive] pub enum ExtendedSignatureError { #[error(transparent)] Ssh(#[from] ssh_key::Error), @@ -128,6 +129,7 @@ pub mod fmt { } #[derive(Debug, Error)] +#[non_exhaustive] pub enum SignatureError { #[error(transparent)] Invalid(#[from] crypto::Error), @@ -164,6 +166,7 @@ impl Encodable for crypto::Signature { } #[derive(Debug, Error)] +#[non_exhaustive] pub enum PublicKeyError { #[error(transparent)] Invalid(#[from] crypto::Error), @@ -199,6 +202,7 @@ impl Encodable for PublicKey { } #[derive(Debug, Error)] +#[non_exhaustive] pub enum SecretKeyError { #[error(transparent)] Encoding(#[from] encoding::Error), diff --git a/crates/radicle-crypto/src/ssh/keystore.rs b/crates/radicle-crypto/src/ssh/keystore.rs index 32b8cf69..49d241ec 100644 --- a/crates/radicle-crypto/src/ssh/keystore.rs +++ b/crates/radicle-crypto/src/ssh/keystore.rs @@ -15,6 +15,7 @@ use super::ExtendedSignature; pub type Passphrase = Zeroizing; #[derive(Debug, Error)] +#[non_exhaustive] pub enum Error { #[error(transparent)] Io(#[from] io::Error), @@ -227,6 +228,7 @@ impl Keystore { } #[derive(Debug, Error)] +#[non_exhaustive] pub enum MemorySignerError { #[error(transparent)] Keystore(#[from] Error),