/// Parse a decrypted Olm message, check that the plaintext and encrypted
/// senders match and that the message was meant for us.
Parse a decrypted Olm message, check that the plaintext and encrypted
senders match and that the message was meant for us.
Parse a decrypted Olm message check that the plaintext and encrypted senders match and that the message was meant for us .
fn parse_decrypted_to_device_event(
        &self,
        sender: &UserId,
        plaintext: String,
    ) -> OlmResult<(Raw<AnyToDeviceEvent>, String)> {
        #[derive(Deserialize)]
        struct DecryptedEvent {
            sender: Box<UserId>,
            recipient: Box<UserId>,
            recipient_keys: OlmV1Keys,
            keys: OlmV1Keys,
        }
        let event: DecryptedEvent = serde_json::from_str(&plaintext)?;
        let identity_keys = self.inner.identity_keys();
        if event.recipient != self.user_id() {
            Err(EventError::MismatchedSender(event.recipient, self.user_id().to_owned()).into())
        } else if event.sender != sender {
            Err(EventError::MismatchedSender(event.sender, sender.to_owned()).into())
        } else if identity_keys.ed25519() != event.recipient_keys.ed25519 {
            Err(EventError::MismatchedKeys(
                identity_keys.ed25519().to_owned(),
                event.recipient_keys.ed25519,
            )
            .into())
        } else {
            Ok((Raw::from_json(RawJsonValue::from_string(plaintext)?), event.keys.ed25519))
        }
    }
fn parse_decrypted_to_device_event ( & self , sender : & UserId , plaintext : String , ) -> OlmResult < ( Raw < AnyToDeviceEvent > , String ) > { # [ derive ( Deserialize ) ] struct DecryptedEvent { sender : Box < UserId > , recipient : Box < UserId > , recipient_keys : OlmV1Keys , keys : OlmV1Keys , } let event : DecryptedEvent = serde_json :: from_str ( & plaintext ) ? ; let identity_keys = self . inner . identity_keys ( ) ; if event . recipient != self . user_id ( ) { Err ( EventError :: MismatchedSender ( event . recipient , self . user_id ( ) . to_owned ( ) ) . into ( ) ) } else if event . sender != sender { Err ( EventError :: MismatchedSender ( event . sender , sender . to_owned ( ) ) . into ( ) ) } else if identity_keys . ed25519 ( ) != event . recipient_keys . ed25519 { Err ( EventError :: MismatchedKeys ( identity_keys . ed25519 ( ) . to_owned ( ) , event . recipient_keys . ed25519 , ) . into ( ) ) } else { Ok ( ( Raw :: from_json ( RawJsonValue :: from_string ( plaintext ) ? ) , event . keys . ed25519 ) ) } }
Parse a decrypted Olm message, check that the plaintext and encrypted
senders match and that the message was meant for us.
Parse a decrypted Olm message check that the plaintext and encrypted senders match and that the message was meant for us .
&self
sender
&UserId
plaintext
String