Add Clone to error

This commit is contained in:
asonix 2020-03-15 21:36:06 -05:00
parent 1b31bd6281
commit 6c47c3fc37
3 changed files with 9 additions and 4 deletions

View file

@ -19,4 +19,5 @@ thiserror = "1.0.9"
yasna = { version = "0.3", features = ["num-bigint"] }
[dev-dependencies]
anyhow = "1.0"
rand = "0.7"

View file

@ -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()?);

View file

@ -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,