Use thiserror
This commit is contained in:
parent
f491286068
commit
9b8b284bb1
|
@ -10,12 +10,12 @@ edition = "2018"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
failure = "0.1"
|
||||
num-bigint = "0.2"
|
||||
num-bigint-dig = "0.4"
|
||||
num-traits = "0.2"
|
||||
pem = "0.4"
|
||||
rsa = "0.1.3"
|
||||
thiserror = "1.0.9"
|
||||
yasna = { version = "0.3", features = ["num-bigint"] }
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
22
src/lib.rs
22
src/lib.rs
|
@ -1,4 +1,4 @@
|
|||
use failure::Fail;
|
||||
use thiserror::Error;
|
||||
use num_bigint_dig::{BigInt, BigUint, Sign};
|
||||
|
||||
mod private;
|
||||
|
@ -17,21 +17,21 @@ pub trait KeyExt {
|
|||
Self: Sized;
|
||||
}
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum KeyError {
|
||||
#[fail(display = "Invalid key kind supplied")]
|
||||
#[error("Invalid key kind supplied")]
|
||||
Kind,
|
||||
|
||||
#[fail(display = "Key not PEM-formatted")]
|
||||
#[error("Key not PEM-formatted")]
|
||||
Pem,
|
||||
|
||||
#[fail(display = "Error parsing key, {}", _0)]
|
||||
Parse(#[cause] yasna::ASN1Error),
|
||||
#[error("Error parsing key, {}", .0)]
|
||||
Parse(#[from] yasna::ASN1Error),
|
||||
|
||||
#[fail(display = "Constructed key is invalid")]
|
||||
#[error("Constructed key is invalid")]
|
||||
Validate,
|
||||
|
||||
#[fail(display = "Could not serialize key")]
|
||||
#[error("Could not serialize key")]
|
||||
Serialize,
|
||||
}
|
||||
|
||||
|
@ -56,12 +56,6 @@ fn sign_from_dig(sign: Sign) -> num_bigint::Sign {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<yasna::ASN1Error> for KeyError {
|
||||
fn from(e: yasna::ASN1Error) -> Self {
|
||||
KeyError::Parse(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::KeyExt;
|
||||
|
|
Loading…
Reference in a new issue