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: i64Current server salt to include in outgoing messages.
time_offset: i32Clock skew in seconds vs. server.
Implementations§
Source§impl EncryptedSession
impl EncryptedSession
Sourcepub fn new(auth_key: [u8; 256], first_salt: i64, time_offset: i32) -> Self
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.
Sourcepub fn pack_serializable<S: Serializable>(&mut self, call: &S) -> Vec<u8> ⓘ
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.
Sourcepub fn pack<R: RemoteCall>(&mut self, call: &R) -> Vec<u8> ⓘ
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.
Sourcepub fn unpack(
&self,
frame: &mut Vec<u8>,
) -> Result<DecryptedMessage, DecryptError>
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).
Sourcepub fn auth_key_bytes(&self) -> [u8; 256]
pub fn auth_key_bytes(&self) -> [u8; 256]
Return the auth_key bytes (for persistence).
Sourcepub fn session_id(&self) -> i64
pub fn session_id(&self) -> i64
Return the current session_id.