use std::fmt::Debug;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum IdentityBuilderError {
#[error("the signature box is too small")]
BoxSizeTooSmall,
#[error("error while generating CBOR ({0})")]
CborGenerationError(String),
#[error("credential-related error ({0})")]
CredentialError(String),
#[error("error while generating signature ({0})")]
SignerError(String),
#[error("internal error ({0})")]
InternalError(String),
}
impl<T: Debug> From<ciborium::ser::Error<T>> for IdentityBuilderError {
fn from(err: ciborium::ser::Error<T>) -> Self {
Self::CborGenerationError(err.to_string())
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::panic)]
#![allow(clippy::unwrap_used)]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test;
use crate::identity::builder::IdentityBuilderError;
#[test]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test
)]
fn impl_from_ciborium_err() {
let ciborium_err: ciborium::ser::Error<String> =
ciborium::ser::Error::Value("foo".to_string());
let builder_err: IdentityBuilderError = ciborium_err.into();
assert_eq!(
builder_err.to_string(),
"error while generating CBOR (Value(\"foo\"))"
);
}
}