use thiserror::Error;
#[derive(Error, Debug)]
pub enum KeystoreError {
#[error("Mac Mismatch")]
MacMismatch,
#[error("IO: {0}")]
StdIo(String),
#[error("serde-json: {0}")]
SerdeJson(String),
#[error("scrypt {0:?}")]
ScryptInvalidParams(scrypt::errors::InvalidParams),
#[error("scrypt {0:?}")]
ScryptInvalidOuputLen(scrypt::errors::InvalidOutputLen),
#[error("aes {0:?}")]
AesInvalidKeyNonceLength(aes::cipher::InvalidLength),
#[cfg(feature = "geth-compat")]
#[error(transparent)]
K256Error(#[from] k256::ecdsa::Error),
}
impl From<scrypt::errors::InvalidParams> for KeystoreError {
fn from(e: scrypt::errors::InvalidParams) -> Self {
Self::ScryptInvalidParams(e)
}
}
impl From<scrypt::errors::InvalidOutputLen> for KeystoreError {
fn from(e: scrypt::errors::InvalidOutputLen) -> Self {
Self::ScryptInvalidOuputLen(e)
}
}
impl From<aes::cipher::InvalidLength> for KeystoreError {
fn from(e: aes::cipher::InvalidLength) -> Self {
Self::AesInvalidKeyNonceLength(e)
}
}
impl From<std::io::Error> for KeystoreError {
fn from(e: std::io::Error) -> KeystoreError {
KeystoreError::StdIo(e.to_string())
}
}
impl From<serde_json::Error> for KeystoreError {
fn from(e: serde_json::Error) -> KeystoreError {
KeystoreError::SerdeJson(e.to_string())
}
}