Merge branch 'remove-boxed-error' into 'main'

remove boxed error variant

Closes #4

See merge request fabinfra/fabaccess/nfc_rs!1
This commit is contained in:
Kai Kriegel 2022-04-21 12:03:41 +00:00
commit a4a15b17f7
2 changed files with 6 additions and 12 deletions

View File

@ -23,15 +23,11 @@ pub struct CipherKey {
impl CipherKey {
pub fn new(key: &[u8], cipher: CipherType, key_version: u8) -> Result<CipherKey> {
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);

View File

@ -4,7 +4,6 @@ use std::io;
#[derive(Debug)]
pub enum Error {
IO(io::Error),
Boxed(Box<dyn std::error::Error>),
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),