use thiserror::Error;
pub type Result<T> = std::result::Result<T, CrablockError>;
#[derive(Error, Debug)]
pub enum CrablockError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Crypto error: {0}")]
Crypto(String),
#[error("Invalid package format: {0}")]
InvalidFormat(String),
#[error("Invalid key: {0}")]
InvalidKey(String),
#[error("Decryption failed: {0}")]
DecryptionFailed(String),
#[error("Verification failed: {0}")]
VerificationFailed(String),
#[error("Key source error: {0}")]
KeySource(String),
#[error("Signature verification failed: {0}")]
SignatureVerification(String),
#[error("Package is unsigned. Use --require-signature to reject unsigned packages.")]
SignatureMissing,
#[error("Signature verification failed. Package may be tampered with or wrong pubkey.")]
SignatureInvalid,
#[error("No pubkey provided. Use --verify-pubkey file:... to verify signed packages.")]
PubKeyMissing,
#[error("Unsupported signature algorithm: {0}. Supported: ed25519.")]
UnsupportedSignatureAlgorithm(String),
#[error("Execution error: {0}")]
Execution(String),
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Permission denied: {0}")]
Permission(String),
#[error("Unsupported algorithm: {0}")]
UnsupportedAlgorithm(String),
#[error("Missing manifest field: {0}")]
MissingManifestField(String),
#[error("Package not found: {0}")]
PackageNotFound(String),
#[error("Invalid package extension for '{path}'. Expected a {expected} file.")]
InvalidPackageExtension { path: String, expected: String },
#[error("Invalid magic bytes")]
InvalidMagic,
#[error("Version mismatch: expected {expected}, found {found}")]
VersionMismatch { expected: u16, found: u16 },
#[error("Hash mismatch: expected {expected}, computed {computed}")]
HashMismatch { expected: String, computed: String },
#[error("Process error: {0}")]
Process(String),
#[error("Configuration error: {0}")]
Config(String),
}