mirror of
https://gitlab.com/fabinfra/fabaccess/nfc_rs.git
synced 2025-03-12 06:41:46 +01:00
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:
commit
a4a15b17f7
@ -23,15 +23,11 @@ pub struct CipherKey {
|
|||||||
impl CipherKey {
|
impl CipherKey {
|
||||||
pub fn new(key: &[u8], cipher: CipherType, key_version: u8) -> Result<CipherKey> {
|
pub fn new(key: &[u8], cipher: CipherType, key_version: u8) -> Result<CipherKey> {
|
||||||
if cipher == AES && key_version < 0x10 {
|
if cipher == AES && key_version < 0x10 {
|
||||||
return Err(Error::Boxed(Box::new(simple_error!(
|
return Err(simple_error!("KeyVersion is to low for AES Key (Minimum = 0x10)").into());
|
||||||
"KeyVersion is to low for AES Key (Minimum = 0x10)"
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !check_key(key, cipher.clone()) {
|
if !check_key(key, cipher.clone()) {
|
||||||
return Err(Error::Boxed(Box::new(simple_error!(
|
return Err(simple_error!("Key is not valid for CipherType").into());
|
||||||
"Key is not valid for CipherType"
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut key: Box<[u8]> = Box::from(key);
|
let mut key: Box<[u8]> = Box::from(key);
|
||||||
|
10
src/error.rs
10
src/error.rs
@ -4,7 +4,6 @@ use std::io;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
IO(io::Error),
|
IO(io::Error),
|
||||||
Boxed(Box<dyn std::error::Error>),
|
|
||||||
Simple(simple_error::SimpleError),
|
Simple(simple_error::SimpleError),
|
||||||
BlockModeError(block_modes::BlockModeError),
|
BlockModeError(block_modes::BlockModeError),
|
||||||
InvalidKeyIvLength(block_modes::InvalidKeyIvLength),
|
InvalidKeyIvLength(block_modes::InvalidKeyIvLength),
|
||||||
@ -42,9 +41,6 @@ impl fmt::Display for Error {
|
|||||||
Error::IO(e) => {
|
Error::IO(e) => {
|
||||||
write!(f, "IO Error: {}", e)
|
write!(f, "IO Error: {}", e)
|
||||||
}
|
}
|
||||||
Error::Boxed(e) => {
|
|
||||||
write!(f, "{}", e)
|
|
||||||
}
|
|
||||||
Error::Simple(e) => {
|
Error::Simple(e) => {
|
||||||
write!(f, "Generic Error: {}", 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.")
|
write!(f, "The application was not found on the card.")
|
||||||
}
|
}
|
||||||
Error::InvalidLength => {
|
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::CardError => None,
|
||||||
Error::ApplicationNotFound => None,
|
Error::ApplicationNotFound => None,
|
||||||
Error::InvalidLength => None,
|
Error::InvalidLength => None,
|
||||||
Error::Boxed(e) => e.source(),
|
|
||||||
Error::Simple(e) => Some(e),
|
Error::Simple(e) => Some(e),
|
||||||
Error::BlockModeError(e) => Some(e),
|
Error::BlockModeError(e) => Some(e),
|
||||||
Error::InvalidKeyIvLength(e) => Some(e),
|
Error::InvalidKeyIvLength(e) => Some(e),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user