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 From<c2pa_cbor::Error> for IdentityBuilderError {
fn from(err: c2pa_cbor::Error) -> 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 = c2pa_cbor::Error::Io(std::io::Error::other("test error"));
let builder_err: IdentityBuilderError = ciborium_err.into();
assert!(builder_err
.to_string()
.contains("error while generating CBOR"));
}
}