ferogram_e2e/lib.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#![cfg_attr(docsrs, feature(doc_cfg))]
16#![doc(html_root_url = "https://docs.rs/ferogram-e2e/0.1.0-b1")]
17#![deny(unsafe_code)]
18
19//! Telegram secret chats (end-to-end encryption) for ferogram.
20//!
21//! This crate is part of [ferogram](https://crates.io/crates/ferogram), an async Rust
22//! MTProto client built by [Ankit Chaubey](https://github.com/ankit-chaubey).
23//!
24//! - Channel: [t.me/Ferogram](https://t.me/Ferogram)
25//! - Chat: [t.me/FerogramChat](https://t.me/FerogramChat)
26//!
27//! Most users should enable the `e2e` feature of the `ferogram` crate and use
28//! `ferogram::e2e`, which re-exports this crate and connects it to `ferogram::Client`.
29//! Use `ferogram-e2e` directly only to drive secret chats from another client by
30//! implementing [`E2eTransport`]; in that case [`E2eClient::request_secret_chat_raw`] takes the
31//! peer's user id and access hash directly.
32//!
33//! # What's in here
34//!
35//! - **Key exchange**: Diffie-Hellman handshake with Telegram's validity checks ([`dh`]).
36//! - **Messages**: MTProto 2.0 encryption of the inner TL layer ([`crypto`], [`tl`]).
37//! - **Files**: per-file AES-256-IGE encryption plus chunked upload ([`upload`]).
38//! - **Chat state**: sequence numbers, TTLs, re-keying, optional binary persistence ([`state`]).
39//! - **High-level API**: [`E2eClient`] to request, accept and use secret chats, and
40//! [`E2eEvent`] for what comes back from the update stream.
41//!
42//! # Security notes
43//!
44//! Persisted chat state (see [`E2eClient::for_session`] and
45//! [`E2eClient::with_persistence`]) contains the 256-byte `auth_key` of every chat,
46//! unencrypted. The file is created with mode `0600` on Unix; on other platforms keep it
47//! somewhere only your process can read.
48//!
49//! # Example
50//!
51//! ```rust,ignore
52//! // With the `e2e` feature of `ferogram` enabled:
53//! use ferogram::e2e::{E2eClient, E2eClientExt, E2eEvent};
54//!
55//! let e2e = E2eClient::new(client.clone());
56//! let chat_id = e2e.request_secret_chat("@username").await?;
57//!
58//! let mut stream = client.stream_updates();
59//! while let Some(update) = stream.next().await {
60//! if let Some(E2eEvent::ChatReady { chat_id }) = e2e.handle_client_update(&update).await? {
61//! e2e.send_text(chat_id, "hello", 0).await?;
62//! }
63//! }
64//! ```
65
66pub mod chat;
67pub mod crypto;
68pub mod dh;
69pub mod error;
70pub mod state;
71pub mod tl;
72pub mod transport;
73pub mod update;
74pub mod upload;
75
76pub use chat::E2eClient;
77pub use error::E2eError;
78pub use ferogram_tl_types::enums::EncryptedFile;
79pub use tl::{
80 DecryptedAction, DecryptedMedia, DecryptedMessage, DecryptedMessageLayer, DocumentAttribute,
81};
82pub use transport::E2eTransport;
83pub use update::E2eEvent;