Skip to main content

auths_pairing_protocol/
error.rs

1use thiserror::Error;
2
3/// Protocol-level errors for the pairing exchange.
4///
5/// Transport-specific errors (relay, mDNS, LAN timeout) are NOT included —
6/// they belong in the transport layer (CLI, server).
7#[derive(Debug, Error)]
8pub enum ProtocolError {
9    #[error("pairing token expired")]
10    Expired,
11
12    #[error("invalid signature")]
13    InvalidSignature,
14
15    #[error("session already consumed")]
16    SessionConsumed,
17
18    #[error("key exchange failed: {0}")]
19    KeyExchangeFailed(String),
20
21    #[error("key generation failed: {0}")]
22    KeyGenFailed(String),
23
24    #[error("invalid pairing URI: {0}")]
25    InvalidUri(String),
26
27    #[error("encryption failed: {0}")]
28    EncryptionFailed(String),
29
30    #[error("decryption failed: {0}")]
31    DecryptionFailed(String),
32
33    #[error("serialization error: {0}")]
34    Serialization(String),
35}
36
37impl From<serde_json::Error> for ProtocolError {
38    fn from(e: serde_json::Error) -> Self {
39        ProtocolError::Serialization(e.to_string())
40    }
41}