Add Clone to error
This commit is contained in:
parent
1b31bd6281
commit
6c47c3fc37
|
@ -19,4 +19,5 @@ thiserror = "1.0.9"
|
||||||
yasna = { version = "0.3", features = ["num-bigint"] }
|
yasna = { version = "0.3", features = ["num-bigint"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
anyhow = "1.0"
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
use failure::Error;
|
use anyhow::Error;
|
||||||
use rsa::RSAPrivateKey;
|
use rsa::RSAPrivateKey;
|
||||||
use rsa_pem::KeyExt;
|
use rsa_pem::KeyExt;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, thiserror::Error)]
|
||||||
|
#[error("Error generating key")]
|
||||||
|
pub struct MyError;
|
||||||
|
|
||||||
fn main() -> Result<(), Error> {
|
fn main() -> Result<(), Error> {
|
||||||
let mut rng = rand::thread_rng();
|
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!("PKCS1 - Private");
|
||||||
println!("{}", key.to_pem_pkcs1()?);
|
println!("{}", key.to_pem_pkcs1()?);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use thiserror::Error;
|
|
||||||
use num_bigint_dig::{BigInt, BigUint, Sign};
|
use num_bigint_dig::{BigInt, BigUint, Sign};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
mod private;
|
mod private;
|
||||||
mod public;
|
mod public;
|
||||||
|
@ -17,7 +17,7 @@ pub trait KeyExt {
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Clone, Debug, Error)]
|
||||||
pub enum KeyError {
|
pub enum KeyError {
|
||||||
#[error("Invalid key kind supplied")]
|
#[error("Invalid key kind supplied")]
|
||||||
Kind,
|
Kind,
|
||||||
|
|
Loading…
Reference in a new issue