From 789340b2cb10de407ecab362d1d576682533ede2 Mon Sep 17 00:00:00 2001 From: Alexander Sieg Date: Sat, 16 Apr 2022 18:50:20 +0200 Subject: [PATCH] remove boxed error variant Without this variant the Error enum is compatiable with eyre and anyhow. Fixes fabinfra/fabaccess/nfc_rs#4 --- src/crypto/cipher_key.rs | 8 ++------ src/error.rs | 10 ++++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/crypto/cipher_key.rs b/src/crypto/cipher_key.rs index d703926..a0555b1 100644 --- a/src/crypto/cipher_key.rs +++ b/src/crypto/cipher_key.rs @@ -23,15 +23,11 @@ pub struct CipherKey { impl CipherKey { pub fn new(key: &[u8], cipher: CipherType, key_version: u8) -> Result { if cipher == AES && key_version < 0x10 { - return Err(Error::Boxed(Box::new(simple_error!( - "KeyVersion is to low for AES Key (Minimum = 0x10)" - )))); + return Err(simple_error!("KeyVersion is to low for AES Key (Minimum = 0x10)").into()); } if !check_key(key, cipher.clone()) { - return Err(Error::Boxed(Box::new(simple_error!( - "Key is not valid for CipherType" - )))); + return Err(simple_error!("Key is not valid for CipherType").into()); } let mut key: Box<[u8]> = Box::from(key); diff --git a/src/error.rs b/src/error.rs index e50026f..7229e89 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,7 +4,6 @@ use std::io; #[derive(Debug)] pub enum Error { IO(io::Error), - Boxed(Box), Simple(simple_error::SimpleError), BlockModeError(block_modes::BlockModeError), InvalidKeyIvLength(block_modes::InvalidKeyIvLength), @@ -42,9 +41,6 @@ impl fmt::Display for Error { Error::IO(e) => { write!(f, "IO Error: {}", e) } - Error::Boxed(e) => { - write!(f, "{}", e) - } Error::Simple(e) => { write!(f, "Generic Error: {}", e) } @@ -139,7 +135,10 @@ impl fmt::Display for Error { write!(f, "The application was not found on the card.") } Error::InvalidLength => { - write!(f, "More data was requested than can be handled in a single transaction.") + write!( + f, + "More data was requested than can be handled in a single transaction." + ) } } } @@ -175,7 +174,6 @@ impl std::error::Error for Error { Error::CardError => None, Error::ApplicationNotFound => None, Error::InvalidLength => None, - Error::Boxed(e) => e.source(), Error::Simple(e) => Some(e), Error::BlockModeError(e) => Some(e), Error::InvalidKeyIvLength(e) => Some(e),