Skip to main content

ferogram_e2e/
error.rs

1/*
2 * Copyright (c) 2026 Ankit Chaubey <ankitchaubey.dev@gmail.com>
3 * https://github.com/ankit-chaubey
4 *
5 * Project: ferogram
6 * Website: https://ferogram.dev
7 *
8 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
9 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
10 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
11 * This file may not be copied, modified, or distributed except according
12 * to those terms.
13 */
14
15//! Error type for the secret chat layer.
16
17use thiserror::Error;
18
19/// Errors returned by `ferogram-e2e`.
20#[derive(Debug, Error)]
21pub enum E2eError {
22    /// A DH value (`g_a`, `g_b`) failed the range checks against the prime.
23    #[error("DH value outside valid range")]
24    DhValidationFailed,
25
26    /// The shared secret computed by the DH exchange is not usable.
27    #[error("computed shared secret is invalid")]
28    SharedSecretInvalid,
29
30    /// The key fingerprint on a message or exchange does not match our key.
31    #[error("key fingerprint mismatch")]
32    KeyFingerprintMismatch,
33
34    /// A message or file could not be decrypted or failed an integrity check.
35    #[error("decryption failed")]
36    DecryptionFailed,
37
38    /// A message or file could not be encrypted.
39    #[error("encryption failed")]
40    EncryptionFailed,
41
42    /// No secret chat with this id is known.
43    #[error("chat not found: {0}")]
44    ChatNotFound(i32),
45
46    /// A secret chat with this id already exists.
47    #[error("chat already exists: {0}")]
48    ChatAlreadyExists(i32),
49
50    /// The chat is not in a state that allows this operation.
51    #[error("invalid state: {0}")]
52    InvalidState(String),
53
54    /// A text message or attachment exceeds the size limit (text: 512 KiB).
55    #[error("message too large")]
56    MessageTooLarge,
57
58    /// A key re-exchange is already in progress for this chat.
59    #[error("re-key already in progress")]
60    RekeyInProgress,
61
62    /// Serializing an inner TL object failed.
63    #[error("TL serialization failed")]
64    TlSerializationFailed,
65
66    /// Parsing an inner TL object failed.
67    #[error("TL deserialization failed")]
68    TlDeserializationFailed,
69
70    /// A re-key security check failed (fingerprint mismatch on accept or commit).
71    #[error("security error: {0}")]
72    SecurityError(String),
73
74    /// The underlying client failed to complete an RPC.
75    #[error("transport: {0}")]
76    Transport(String),
77
78    /// Uploading an encrypted file failed.
79    #[error("file upload failed: {0}")]
80    UploadFailed(String),
81
82    /// The file exceeds the 2 GB limit.
83    #[error("file too large (max 2 GB)")]
84    FileTooLarge,
85}