Skip to main content

auths_core/pairing/
error.rs

1//! Pairing protocol error types.
2
3use thiserror::Error;
4
5/// Errors that can occur during the pairing protocol.
6#[derive(Debug, Error)]
7pub enum PairingError {
8    /// Random number generation failed.
9    #[error("RNG failed: {0}")]
10    RngFailed(String),
11
12    /// Key generation failed.
13    #[error("Key generation failed: {0}")]
14    KeyGenFailed(String),
15
16    /// The pairing token has expired.
17    #[error("Pairing token expired")]
18    Expired,
19
20    /// Invalid signature in the pairing response.
21    #[error("Invalid signature")]
22    InvalidSignature,
23
24    /// Invalid pairing URI format.
25    #[error("Invalid URI format: {0}")]
26    InvalidUri(String),
27
28    /// Invalid short code format.
29    #[error("Invalid short code: {0}")]
30    InvalidShortCode(String),
31
32    /// QR code generation failed.
33    #[error("QR code generation failed: {0}")]
34    QrCodeFailed(String),
35
36    /// Serialization error.
37    #[error("Serialization error: {0}")]
38    Serialization(String),
39
40    /// X25519 key exchange failed.
41    #[error("Key exchange failed: {0}")]
42    KeyExchangeFailed(String),
43
44    /// Ephemeral secret already consumed (one-time use).
45    #[error("Session ephemeral secret already consumed")]
46    SessionConsumed,
47
48    /// Short code not found in registry.
49    #[error("Short code not found: {0}")]
50    ShortCodeNotFound(String),
51
52    /// Network error during relay communication.
53    #[error("Relay error: {0}")]
54    RelayError(String),
55
56    /// Local LAN server error.
57    #[error("Local server error: {0}")]
58    LocalServerError(String),
59
60    /// mDNS advertisement or discovery error.
61    #[error("mDNS error: {0}")]
62    MdnsError(String),
63
64    /// No peer found on the local network.
65    #[error("No peer found on local network")]
66    NoPeerFound,
67
68    /// LAN pairing timed out waiting for a response.
69    #[error("LAN pairing timed out")]
70    LanTimeout,
71}
72
73impl From<serde_json::Error> for PairingError {
74    fn from(e: serde_json::Error) -> Self {
75        PairingError::Serialization(e.to_string())
76    }
77}