1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, CrablockError>;
5
6#[derive(Error, Debug)]
7pub enum CrablockError {
8 #[error("IO error: {0}")]
9 Io(#[from] std::io::Error),
10
11 #[error("Crypto error: {0}")]
12 Crypto(String),
13
14 #[error("Invalid package format: {0}")]
15 InvalidFormat(String),
16
17 #[error("Invalid key: {0}")]
18 InvalidKey(String),
19
20 #[error("Decryption failed: {0}")]
21 DecryptionFailed(String),
22
23 #[error("Verification failed: {0}")]
24 VerificationFailed(String),
25
26 #[error("Key source error: {0}")]
27 KeySource(String),
28
29 #[error("Signature verification failed: {0}")]
30 SignatureVerification(String),
31
32 #[error("Package is unsigned. Use --require-signature to reject unsigned packages.")]
33 SignatureMissing,
34
35 #[error("Signature verification failed. Package may be tampered with or wrong pubkey.")]
36 SignatureInvalid,
37
38 #[error("No pubkey provided. Use --verify-pubkey file:... to verify signed packages.")]
39 PubKeyMissing,
40
41 #[error("Unsupported signature algorithm: {0}. Supported: ed25519.")]
42 UnsupportedSignatureAlgorithm(String),
43
44 #[error("Execution error: {0}")]
45 Execution(String),
46
47 #[error("Serialization error: {0}")]
48 Serialization(String),
49
50 #[error("Permission denied: {0}")]
51 Permission(String),
52
53 #[error("Unsupported algorithm: {0}")]
54 UnsupportedAlgorithm(String),
55
56 #[error("Missing manifest field: {0}")]
57 MissingManifestField(String),
58
59 #[error("Package not found: {0}")]
60 PackageNotFound(String),
61
62 #[error("Invalid package extension for '{path}'. Expected a {expected} file.")]
63 InvalidPackageExtension { path: String, expected: String },
64
65 #[error("Invalid magic bytes")]
66 InvalidMagic,
67
68 #[error("Version mismatch: expected {expected}, found {found}")]
69 VersionMismatch { expected: u16, found: u16 },
70
71 #[error("Hash mismatch: expected {expected}, computed {computed}")]
72 HashMismatch { expected: String, computed: String },
73
74 #[error("Process error: {0}")]
75 Process(String),
76
77 #[error("Configuration error: {0}")]
78 Config(String),
79}