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("RNG failure: {0}")]
25    RngFailed(String),
26
27    #[error("invalid pairing URI: {0}")]
28    InvalidUri(String),
29
30    #[error("invalid short code: {0}")]
31    InvalidShortCode(String),
32
33    #[error("short code not found: {0}")]
34    ShortCodeNotFound(String),
35
36    #[error("encryption failed: {0}")]
37    EncryptionFailed(String),
38
39    #[error("decryption failed: {0}")]
40    DecryptionFailed(String),
41
42    #[error("serialization error: {0}")]
43    Serialization(String),
44}
45
46impl From<serde_json::Error> for ProtocolError {
47    fn from(e: serde_json::Error) -> Self {
48        ProtocolError::Serialization(e.to_string())
49    }
50}