use affinidi_secrets_resolver::secrets::KeyType;
use thiserror::Error;
use crate::crypto_suites::CryptoSuite;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum SignatureFailure {
Malformed,
Invalid,
}
impl std::fmt::Display for SignatureFailure {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Malformed => f.write_str("malformed"),
Self::Invalid => f.write_str("invalid"),
}
}
}
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum DataIntegrityError {
#[error("unsupported cryptosuite: {name}")]
UnsupportedCryptoSuite { name: String },
#[error(
"key type {actual:?} is not compatible with cryptosuite {suite:?} (expected {expected:?})"
)]
KeyTypeMismatch {
expected: KeyType,
actual: KeyType,
suite: CryptoSuite,
},
#[error("signature {reason} for cryptosuite {suite:?}")]
InvalidSignature {
suite: CryptoSuite,
reason: SignatureFailure,
},
#[error("invalid public key (codec={codec:?}, len={len}): {reason}")]
InvalidPublicKey {
codec: Option<u64>,
len: usize,
reason: String,
},
#[error("canonicalization failed: {0}")]
Canonicalization(String),
#[error("malformed proof: {0}")]
MalformedProof(String),
#[error("spec conformance check failed: {0}")]
Conformance(String),
#[error("signing failed")]
Signing(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error("resolver error: {0}")]
Resolver(String),
}
impl DataIntegrityError {
pub fn signing<E>(e: E) -> Self
where
E: std::error::Error + Send + Sync + 'static,
{
Self::Signing(Box::new(e))
}
}