use sigstore_crypto::SubjectAltName;
use thiserror::Error;
use crate::IdentityMatcher;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("identity mismatch: expected {expected}, got {}", display_opt(actual))]
IdentityMismatch {
expected: IdentityMatcher,
actual: Option<SubjectAltName>,
},
#[error("issuer mismatch: expected {expected}, got {}", display_opt(actual))]
IssuerMismatch {
expected: String,
actual: Option<String>,
},
#[error("Verification error: {0}")]
Verification(String),
#[error("Types error: {0}")]
Types(#[from] sigstore_types::Error),
#[error("Crypto error: {0}")]
Crypto(#[from] sigstore_crypto::Error),
#[error("Bundle error: {0}")]
Bundle(#[from] sigstore_bundle::Error),
#[error("Trust root error: {0}")]
TrustRoot(#[from] sigstore_trust_root::Error),
#[error("invalid trusted certificate: {0}")]
TrustedCertificate(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error("failed to read artifact: {0}")]
ArtifactRead(#[source] std::io::Error),
}
fn display_opt(value: &Option<impl std::fmt::Display>) -> String {
value
.as_ref()
.map_or_else(|| "none".to_string(), ToString::to_string)
}
pub type Result<T> = std::result::Result<T, Error>;