use crate::{PrivateKeyError, PublicKeyError};
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Error {
v: String,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.v)
}
}
impl From<k256::elliptic_curve::Error> for Error {
fn from(err: k256::elliptic_curve::Error) -> Self {
Error { v: err.to_string() }
}
}
impl From<k256::ecdsa::Error> for Error {
fn from(err: k256::ecdsa::Error) -> Self {
Error { v: err.to_string() }
}
}
impl From<&'static str> for Error {
fn from(err: &str) -> Self {
Error { v: err.to_string() }
}
}
impl From<String> for Error {
fn from(err: String) -> Self {
Error { v: err }
}
}
impl From<hex::FromHexError> for Error {
fn from(err: hex::FromHexError) -> Self {
Error { v: err.to_string() }
}
}
impl From<PrivateKeyError> for Error {
fn from(err: PrivateKeyError) -> Self {
Error { v: err.to_string() }
}
}
impl From<PublicKeyError> for Error {
fn from(err: PublicKeyError) -> Self {
Error { v: err.to_string() }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error() {
let err = Error::from("test");
assert_eq!(err.to_string(), "test");
}
}