From 6c47c3fc377375a5bfedbb7457832fc013d3227d Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 15 Mar 2020 21:36:06 -0500 Subject: [PATCH] Add Clone to error --- Cargo.toml | 1 + examples/generate.rs | 8 ++++++-- src/lib.rs | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1a45d4f..795635c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,4 +19,5 @@ thiserror = "1.0.9" yasna = { version = "0.3", features = ["num-bigint"] } [dev-dependencies] +anyhow = "1.0" rand = "0.7" diff --git a/examples/generate.rs b/examples/generate.rs index a8f8da3..1a155e1 100644 --- a/examples/generate.rs +++ b/examples/generate.rs @@ -1,11 +1,15 @@ -use failure::Error; +use anyhow::Error; use rsa::RSAPrivateKey; use rsa_pem::KeyExt; +#[derive(Clone, Debug, thiserror::Error)] +#[error("Error generating key")] +pub struct MyError; + fn main() -> Result<(), Error> { let mut rng = rand::thread_rng(); - let key = RSAPrivateKey::new(&mut rng, 2048)?; + let key = RSAPrivateKey::new(&mut rng, 2048).map_err(|_| MyError)?; println!("PKCS1 - Private"); println!("{}", key.to_pem_pkcs1()?); diff --git a/src/lib.rs b/src/lib.rs index 24dfa9a..54f1902 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ -use thiserror::Error; use num_bigint_dig::{BigInt, BigUint, Sign}; +use thiserror::Error; mod private; mod public; @@ -17,7 +17,7 @@ pub trait KeyExt { Self: Sized; } -#[derive(Debug, Error)] +#[derive(Clone, Debug, Error)] pub enum KeyError { #[error("Invalid key kind supplied")] Kind,