1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum EnvelopeError {
8 #[error("signature verification failed: {0}")]
10 InvalidSignature(#[from] ed25519_dalek::SignatureError),
11
12 #[error("PQ signature verification failed: {0}")]
14 PqSignatureInvalid(String),
15
16 #[error("signer pubkey mismatch: expected {expected}, got {actual}")]
18 SignerMismatch { expected: String, actual: String },
19
20 #[error("invalid public key: expected {expected} bytes, got {actual}")]
22 InvalidPublicKey { expected: usize, actual: usize },
23
24 #[error("envelope serialization failed: {0}")]
26 Serialization(#[from] capnp::Error),
27
28 #[error("envelope schema error: {0}")]
30 Schema(#[from] capnp::NotInSchema),
31
32 #[error("HMAC verification failed")]
34 InvalidHmac,
35
36 #[error("key exchange failed: {0}")]
38 KeyExchange(String),
39
40 #[error("missing required field: {0}")]
42 MissingField(&'static str),
43
44 #[error("replay attack detected: {0}")]
46 ReplayAttack(String),
47
48 #[error("invalid topic format: expected valid hex string")]
50 InvalidTopicFormat,
51
52 #[error("encryption failed: {0}")]
54 Encryption(String),
55
56 #[error("decryption failed: {0}")]
58 Decryption(String),
59
60 #[error("MAC verification failed")]
62 MacVerification,
63}
64
65pub type EnvelopeResult<T> = std::result::Result<T, EnvelopeError>;
67
68#[derive(Debug, Error)]
70pub enum RpcError {
71 #[error("envelope error: {0}")]
73 Envelope(#[from] EnvelopeError),
74
75 #[error("spawn failed: {0}")]
77 SpawnFailed(String),
78
79 #[error("stop failed: {0}")]
81 StopFailed(String),
82
83 #[error("invalid operation: {0}")]
85 InvalidOperation(String),
86
87 #[error("io error: {0}")]
89 Io(#[from] std::io::Error),
90
91 #[error("{0}")]
93 Other(String),
94}
95
96pub type Result<T> = std::result::Result<T, RpcError>;