1use thiserror::Error;
4
5#[non_exhaustive]
7#[derive(Error, Debug)]
8pub enum Error {
9 #[error("Invalid signature")]
10 InvalidSignature,
11
12 #[error("Invalid public key: {0}")]
13 InvalidPublicKey(String),
14
15 #[error("Invalid private key")]
16 InvalidPrivateKey,
17
18 #[error("Invalid hex encoding: {0}")]
19 InvalidHex(String),
20
21 #[error("Invalid hash length: expected {expected}, got {actual}")]
22 InvalidHashLength { expected: usize, actual: usize },
23
24 #[error("Merkle proof verification failed")]
25 MerkleProofFailed,
26
27 #[error("Empty tree: cannot compute root")]
28 EmptyTree,
29
30 #[error("Invalid proof: leaf index {index} out of bounds for tree with {leaves} leaves")]
31 InvalidProofIndex { index: usize, leaves: usize },
32
33 #[error("JSON serialization error: {0}")]
34 JsonError(String),
35
36 #[error("Receipt verification failed: {0}")]
37 ReceiptVerificationFailed(String),
38
39 #[error("Invalid receipt version: {version}")]
40 InvalidReceiptVersion { version: String },
41
42 #[error("Unsupported receipt version: {found} (supported: {supported})")]
43 UnsupportedReceiptVersion { found: String, supported: String },
44
45 #[error("IO error: {0}")]
46 IoError(String),
47
48 #[error("TPM error: {0}")]
49 TpmError(String),
50}
51
52impl From<serde_json::Error> for Error {
53 fn from(e: serde_json::Error) -> Self {
54 Error::JsonError(e.to_string())
55 }
56}
57
58impl From<std::io::Error> for Error {
59 fn from(e: std::io::Error) -> Self {
60 Error::IoError(e.to_string())
61 }
62}
63
64pub type Result<T> = std::result::Result<T, Error>;