aries_bbssignatures/
errors.rsuse thiserror::Error;
#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;
use crate::pok_sig::PoKOfSignatureProofStatus;
#[derive(Debug, Error, Clone)]
pub enum BBSErrorKind {
#[error("Key generation error")]
KeyGenError,
#[error("Public key to message mismatch. Expected {0}, found {1}")]
PublicKeyGeneratorMessageCountMismatch(usize, usize),
#[error("Signature incorrect size. Expected 193, found {0}")]
SignatureIncorrectSize(usize),
#[error("Signature cannot be loaded due to a bad value")]
SignatureValueIncorrectSize,
#[error("Malformed signature")]
MalformedSignature,
#[error("Malformed secret key")]
MalformedSecretKey,
#[error("Malformed public key")]
MalformedPublicKey,
#[error("Signature proof-of-knowledge error: {msg}")]
SignaturePoKError {
msg: String,
},
#[error("Invalid number of bytes. Expected {0}, found {1}")]
InvalidNumberOfBytes(usize, usize),
#[error("The proof failed due to {status}")]
InvalidProof {
status: PoKOfSignatureProofStatus,
},
#[error("{msg}")]
GeneralError {
msg: String,
},
}
#[derive(Debug, Error, Clone)]
#[error(transparent)]
pub struct BBSError {
#[from]
inner: BBSErrorKind,
}
impl BBSError {
pub fn from_kind(kind: BBSErrorKind) -> Self {
BBSError { inner: kind }
}
pub fn kind(&self) -> &BBSErrorKind {
&self.inner
}
}
impl From<String> for BBSError {
fn from(msg: String) -> BBSError {
BBSError::from_kind(BBSErrorKind::GeneralError { msg })
}
}
impl From<std::io::Error> for BBSError {
fn from(err: std::io::Error) -> BBSError {
BBSError::from(format!("{:?}", err))
}
}
#[cfg(feature = "wasm")]
impl From<BBSError> for JsValue {
fn from(error: BBSError) -> Self {
JsValue::from_str(&format!("{}", error))
}
}
#[cfg(feature = "wasm")]
impl From<JsValue> for BBSError {
fn from(js: JsValue) -> Self {
if js.is_string() {
BBSError::from(BBSErrorKind::GeneralError {
msg: js.as_string().unwrap(),
})
} else {
BBSError::from(BBSErrorKind::GeneralError {
msg: "".to_string(),
})
}
}
}
#[cfg(feature = "wasm")]
impl From<serde_wasm_bindgen::Error> for BBSError {
fn from(err: serde_wasm_bindgen::Error) -> Self {
BBSError::from(BBSErrorKind::GeneralError {
msg: format!("{:?}", err),
})
}
}
#[cfg(feature = "wasm")]
impl From<BBSError> for serde_wasm_bindgen::Error {
fn from(err: BBSError) -> Self {
serde_wasm_bindgen::Error::new(err)
}
}