Skip to main content

Crate ferogram_mtproto

Crate ferogram_mtproto 

Source
Expand description

MTProto 2.0 session management, message framing, DH key exchange, and transport abstractions.

This crate is part of ferogram, an async Rust MTProto client built by Ankit Chaubey.

Most users do not need this crate directly. Use the ferogram crate. This is for anyone building a lower-level MTProto stack on top of the crypto and framing primitives.

§Modules

  • authentication: Sans-IO DH key exchange (steps 1-3 + finish). Does no I/O itself; you drive it by passing the serialized requests over your own transport and feeding back the responses.
  • encrypted: EncryptedSession: packs and unpacks MTProto 2.0 encrypted messages once you have a finished AuthKey.
  • session: Session: tracks plaintext sequence numbers and message IDs for the pre-auth handshake phase.
  • transport: [Transport] trait + [AbridgedTransport] and [ObfuscatedAbridged] implementations over any Read + Write stream.
  • message: Message and MessageId framing types.
  • bind_temp_key: Helpers for binding a temporary auth key to a permanent one (used by CDN and multi-DC flows).

§DH handshake flow

let (req, s1) = authentication::step1()?;
// serialize req, send over transport, receive resp (ResPQ)
let (req, s2) = authentication::step2(s1, resp, dc_id)?;
// serialize req, send, receive resp (ServerDhParams)
let (req, s3) = authentication::step3(s2, resp)?;
// serialize req, send, receive resp (SetClientDhParamsAnswer)
let result = authentication::finish(s3, resp)?;
// FinishResult::Done(d)  =>  d.auth_key is your 256-byte session key
// FinishResult::Retry    =>  call retry_step3() + finish(), up to 5 times

§Encrypted session

use ferogram_mtproto::{EncryptedSession, authentication};

let mut session = EncryptedSession::new(auth_key, first_salt, time_offset);

// Pack an RPC call into an encrypted MTProto message
// let wire = session.pack(&my_tl_function);
// transport.send_message(&wire)?;

// Unpack a received message
// let decrypted = session.unpack(&mut raw_bytes)?;
// decrypted.body contains the TL-serialized response

§Transport

Implement transport::Transport over any byte stream to get MTProto framing for free. Two built-in implementations are provided:

Re-exports§

pub use authentication::Finished;
pub use authentication::finish;
pub use authentication::step1;
pub use authentication::step2;
pub use authentication::step3;
pub use bind_temp_key::encrypt_bind_inner;
pub use bind_temp_key::gen_msg_id;
pub use bind_temp_key::serialize_bind_temp_auth_key;
pub use encrypted::DecryptedMessage;
pub use encrypted::EncryptedSession;
pub use encrypted::SeenMsgIds;
pub use encrypted::new_seen_msg_ids;
pub use message::Message;
pub use message::MessageId;
pub use session::Session;

Modules§

authentication
MTProto authentication key generation (DH handshake steps).
bind_temp_key
Temporary/permanent auth key binding via bindTempAuthKey.
encrypted
Encrypted MTProto message construction and parsing.
message
MTProto message framing and container types.
session
Session state: sequence numbers, salt, and server time.
transport
Transport-layer encoding (abridged, intermediate, padded).