zoe_client/pqxdh/
error.rs

1use thiserror::Error;
2use tracing::error;
3
4/// Error type for PQXDH protocol operations
5///
6/// This error type wraps all possible errors that can occur during PQXDH
7/// protocol operations, providing structured error handling with proper
8/// error context and conversion from underlying error types.
9///
10/// ## Error Categories
11///
12/// ### Connection and Service Errors
13/// - [`InboxNotFound`](PqxdhError::InboxNotFound): Service provider inbox not available
14/// - [`ServiceNotPublished`](PqxdhError::ServiceNotPublished): Service must be published first
15/// - [`NoInboxSubscription`](PqxdhError::NoInboxSubscription): Missing inbox subscription
16/// - [`InboxAlreadyPublished`](PqxdhError::InboxAlreadyPublished): Inbox already exists
17///
18/// ### Session Management Errors  
19/// - [`SessionNotFound`](PqxdhError::SessionNotFound): No active session for given ID
20/// - [`InvalidSender`](PqxdhError::InvalidSender): Message from wrong sender (security issue)
21/// - [`NotInitialMessage`](PqxdhError::NotInitialMessage): Expected initial PQXDH message
22///
23/// ### Cryptographic Errors
24/// - [`Crypto`](PqxdhError::Crypto): General cryptographic operation failures
25/// - [`KeyGeneration`](PqxdhError::KeyGeneration): Key generation failures
26/// - [`PqxdhProtocol`](PqxdhError::PqxdhProtocol): Wire protocol PQXDH errors
27///
28/// ### Message and Data Errors
29/// - [`InvalidContentType`](PqxdhError::InvalidContentType): Wrong message content type
30/// - [`NotPqxdhMessage`](PqxdhError::NotPqxdhMessage): Expected PQXDH encrypted message
31/// - [`NoContent`](PqxdhError::NoContent): Message missing content
32/// - [`MessageCreation`](PqxdhError::MessageCreation): Failed to create message
33///
34/// ### Infrastructure Errors
35/// - [`Rpc`](PqxdhError::Rpc): RPC communication failures
36/// - [`MessagesService`](PqxdhError::MessagesService): Message service errors
37/// - [`Serialization`](PqxdhError::Serialization): Postcard serialization errors
38/// - [`SystemTime`](PqxdhError::SystemTime): System time errors
39#[derive(Error, Debug)]
40pub enum PqxdhError {
41    #[error("Inbox not found for service provider")]
42    InboxNotFound,
43
44    #[error("No content found in inbox message")]
45    NoContent,
46
47    #[error("Serialization error: {0}")]
48    Serialization(#[from] postcard::Error),
49
50    #[error("System time error: {0}")]
51    SystemTime(#[from] std::time::SystemTimeError),
52
53    #[error("Message creation failed: {0}")]
54    MessageCreation(String),
55
56    #[error("RPC error: {0}")]
57    Rpc(#[from] tarpc::client::RpcError),
58
59    #[error("Messages service error: {0}")]
60    MessagesService(#[from] crate::ClientError),
61
62    #[error("Cryptographic error: {0}")]
63    Crypto(String),
64
65    #[error("Session not found for session ID")]
66    SessionNotFound,
67
68    #[error("Invalid message content type")]
69    InvalidContentType,
70
71    #[error("No private keys available")]
72    NoPrivateKeys,
73
74    #[error("No inbox available")]
75    NoInbox,
76
77    #[error("Not an initial PQXDH message")]
78    NotInitialMessage,
79
80    #[error("Message not from session sender - potentially compromised")]
81    InvalidSender,
82
83    #[error("Not a PQXDH encrypted message")]
84    NotPqxdhMessage,
85
86    #[error("Inbox already published, use force_overwrite to overwrite")]
87    InboxAlreadyPublished,
88
89    #[error("Must call publish_service() before listening for clients")]
90    ServiceNotPublished,
91
92    #[error("No inbox subscription found - did you call publish_service()?")]
93    NoInboxSubscription,
94
95    #[error("PQXDH key generation failed: {0}")]
96    KeyGeneration(String),
97
98    #[error("PQXDH protocol error: {0}")]
99    PqxdhProtocol(#[from] zoe_wire_protocol::inbox::pqxdh::PqxdhError),
100
101    #[error("Message service error: {0}")]
102    MessageService(#[from] zoe_wire_protocol::MessageError),
103}
104
105/// Result type for PQXDH protocol operations
106pub type Result<T> = std::result::Result<T, PqxdhError>;