Skip to main content

hyprstream_rpc/
error.rs

1//! Error types for the RPC system.
2
3use thiserror::Error;
4
5/// Errors that can occur during envelope operations.
6#[derive(Debug, Error)]
7pub enum EnvelopeError {
8    /// Signature verification failed.
9    #[error("signature verification failed: {0}")]
10    InvalidSignature(#[from] ed25519_dalek::SignatureError),
11
12    /// Post-quantum signature verification failed.
13    #[error("PQ signature verification failed: {0}")]
14    PqSignatureInvalid(String),
15
16    /// Signer public key doesn't match expected key.
17    #[error("signer pubkey mismatch: expected {expected}, got {actual}")]
18    SignerMismatch { expected: String, actual: String },
19
20    /// Invalid public key format.
21    #[error("invalid public key: expected {expected} bytes, got {actual}")]
22    InvalidPublicKey { expected: usize, actual: usize },
23
24    /// Cap'n Proto serialization/deserialization failed.
25    #[error("envelope serialization failed: {0}")]
26    Serialization(#[from] capnp::Error),
27
28    /// Cap'n Proto schema mismatch.
29    #[error("envelope schema error: {0}")]
30    Schema(#[from] capnp::NotInSchema),
31
32    /// HMAC verification failed.
33    #[error("HMAC verification failed")]
34    InvalidHmac,
35
36    /// Key exchange failed.
37    #[error("key exchange failed: {0}")]
38    KeyExchange(String),
39
40    /// Missing required field.
41    #[error("missing required field: {0}")]
42    MissingField(&'static str),
43
44    /// Replay attack detected (duplicate nonce or old timestamp).
45    #[error("replay attack detected: {0}")]
46    ReplayAttack(String),
47
48    /// Invalid topic format (not valid hex).
49    #[error("invalid topic format: expected valid hex string")]
50    InvalidTopicFormat,
51
52    /// AES-GCM encryption failed.
53    #[error("encryption failed: {0}")]
54    Encryption(String),
55
56    /// AES-GCM decryption failed (wrong key, tampered ciphertext, or AAD mismatch).
57    #[error("decryption failed: {0}")]
58    Decryption(String),
59
60    /// MAC verification failed.
61    #[error("MAC verification failed")]
62    MacVerification,
63}
64
65/// Result type alias for envelope operations.
66pub type EnvelopeResult<T> = std::result::Result<T, EnvelopeError>;
67
68/// Errors that can occur during RPC operations.
69#[derive(Debug, Error)]
70pub enum RpcError {
71    /// Envelope error.
72    #[error("envelope error: {0}")]
73    Envelope(#[from] EnvelopeError),
74
75    /// Process spawn failed.
76    #[error("spawn failed: {0}")]
77    SpawnFailed(String),
78
79    /// Process stop failed.
80    #[error("stop failed: {0}")]
81    StopFailed(String),
82
83    /// Invalid operation for this backend/mode.
84    #[error("invalid operation: {0}")]
85    InvalidOperation(String),
86
87    /// IO error.
88    #[error("io error: {0}")]
89    Io(#[from] std::io::Error),
90
91    /// Other error.
92    #[error("{0}")]
93    Other(String),
94}
95
96/// Result type alias for RPC operations.
97pub type Result<T> = std::result::Result<T, RpcError>;