async fn decrypt_with_existing_sessions(
        &self,
        sender: &UserId,
        sender_key: &str,
        message: &OlmMessage,
    ) -> OlmResult<Option<(Session, String)>> {
        let s = self.store.get_sessions(sender_key).await?;

        // We don't have any existing sessions, return early.
        let sessions = if let Some(s) = s {
            s
        } else {
            return Ok(None);
        };

        let mut decrypted: Option<(Session, String)> = None;

        for session in &mut *sessions.lock().await {
            let mut matches = false;

            // If this is a pre-key message check if it was encrypted for our
            // session, if it wasn't decryption will fail so no need to try.
            if let OlmMessage::PreKey(m) = &message {
                matches = session.matches(sender_key, m.clone()).await?;

                if !matches {
                    continue;
                }
            }

            let ret = session.decrypt(message.clone()).await;

            match ret {
                Ok(p) => {
                    decrypted = Some((session.clone(), p));
                    break;
                }
                Err(e) => {
                    // Decryption failed with a matching session, the session is
                    // likely wedged and needs to be rotated.
                    if matches {
                        warn!(
                            sender = sender.as_str(),
                            sender_key = sender_key,
                            error =? e,
                            "Found a matching Olm session yet decryption failed",
                        );
                        return Err(OlmError::SessionWedged(
                            sender.to_owned(),
                            sender_key.to_owned(),
                        ));
                    }
                }
            }
        }

        Ok(decrypted)
    }
/// Try to decrypt an Olm message.
///
/// This try to decrypt an Olm message using all the sessions we share
/// with the given sender.
Try to decrypt an Olm message.
This try to decrypt an Olm message using all the sessions we share
with the given sender.
Try to decrypt an Olm message . This try to decrypt an Olm message using all the sessions we share with the given sender .
async fn decrypt_with_existing_sessions(
        &self,
        sender: &UserId,
        sender_key: &str,
        message: &OlmMessage,
    ) -> OlmResult<Option<(Session, String)>> {
        let s = self.store.get_sessions(sender_key).await?;
        // We don't have any existing sessions, return early.
        let sessions = if let Some(s) = s {
            s
        } else {
            return Ok(None);
        };
        let mut decrypted: Option<(Session, String)> = None;
        for session in &mut *sessions.lock().await {
            let mut matches = false;
            // If this is a pre-key message check if it was encrypted for our
            // session, if it wasn't decryption will fail so no need to try.
            if let OlmMessage::PreKey(m) = &message {
                matches = session.matches(sender_key, m.clone()).await?;
                if !matches {
                    continue;
                }
            }
            let ret = session.decrypt(message.clone()).await;
            match ret {
                Ok(p) => {
                    decrypted = Some((session.clone(), p));
                    break;
                }
                Err(e) => {
                    // Decryption failed with a matching session, the session is
                    // likely wedged and needs to be rotated.
                    if matches {
                        warn!(
                            sender = sender.as_str(),
                            sender_key = sender_key,
                            error =? e,
                            "Found a matching Olm session yet decryption failed",
                        );
                        return Err(OlmError::SessionWedged(
                            sender.to_owned(),
                            sender_key.to_owned(),
                        ));
                    }
                }
            }
        }
        Ok(decrypted)
    }
async fn decrypt_with_existing_sessions ( & self , sender : & UserId , sender_key : & str , message : & OlmMessage , ) -> OlmResult < Option < ( Session , String ) > > { let s = self . store . get_sessions ( sender_key ) . await ? ; // We don't have any existing sessions, return early. let sessions = if let Some ( s ) = s { s } else { return Ok ( None ) ; } ; let mut decrypted : Option < ( Session , String ) > = None ; for session in & mut * sessions . lock ( ) . await { let mut matches = false ; // If this is a pre-key message check if it was encrypted for our // session, if it wasn't decryption will fail so no need to try. if let OlmMessage :: PreKey ( m ) = & message { matches = session . matches ( sender_key , m . clone ( ) ) . await ? ; if ! matches { continue ; } } let ret = session . decrypt ( message . clone ( ) ) . await ; match ret { Ok ( p ) => { decrypted = Some ( ( session . clone ( ) , p ) ) ; break ; } Err ( e ) => { // Decryption failed with a matching session, the session is // likely wedged and needs to be rotated. if matches { warn ! ( sender sender as_str ( ) sender_key sender_key error e " " ) ; return Err ( OlmError :: SessionWedged ( sender . to_owned ( ) , sender_key . to_owned ( ) , ) ) ; } } } } Ok ( decrypted ) }
Try to decrypt an Olm message.
Try to decrypt an Olm message .
&self
sender
&UserId
sender_key
&str
message
&OlmMessage
&self
sender
&UserId
sender_key
&str
message
&OlmMessage