Skip to main content

EncryptedSession

Struct EncryptedSession 

Source
pub struct EncryptedSession {
    pub salt: i64,
    pub time_offset: i32,
    /* private fields */
}
Expand description

MTProto 2.0 encrypted session state.

Wraps an AuthKey and tracks per-session counters (session_id, seq_no, last_msg_id, server salt). Use EncryptedSession::pack to encrypt outgoing requests and EncryptedSession::unpack to decrypt incoming server frames.

Fields§

§salt: i64

Current server salt to include in outgoing messages.

§time_offset: i32

Clock skew in seconds vs. server.

Implementations§

Source§

impl EncryptedSession

Source

pub fn new(auth_key: [u8; 256], first_salt: i64, time_offset: i32) -> Self

Create a new encrypted session from the output of authentication::finish.

Source

pub fn pack_serializable<S: Serializable>(&mut self, call: &S) -> Vec<u8>

Serialize and encrypt a TL function into a wire-ready byte vector.

Layout of the plaintext before encryption:

salt:       i64
session_id: i64
msg_id:     i64
seq_no:     i32
body_len:   i32
body:       [u8; body_len]

Like pack but only requires Serializable (not RemoteCall). Useful for generic wrapper types like InvokeWithLayer<InitConnection<X>> where the return type is determined by the inner call, not the wrapper.

Source

pub fn pack<R: RemoteCall>(&mut self, call: &R) -> Vec<u8>

Encrypt and frame a RemoteCall into a ready-to-send MTProto message.

Returns the encrypted bytes to pass directly to the transport layer.

Source

pub fn unpack( &self, frame: &mut Vec<u8>, ) -> Result<DecryptedMessage, DecryptError>

Decrypt an encrypted server frame.

frame should be a raw frame received from the transport (already stripped of the abridged-length prefix).

Source

pub fn auth_key_bytes(&self) -> [u8; 256]

Return the auth_key bytes (for persistence).

Source

pub fn session_id(&self) -> i64

Return the current session_id.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.