pub async fn verify_backup(
        &self,
        mut serialized_auth_data: Value,
    ) -> Result<bool, CryptoStoreError> {
        #[derive(Debug, Serialize, Deserialize)]
        struct AuthData {
            public_key: String,
            #[serde(default)]
            signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
            #[serde(flatten)]
            extra: BTreeMap<String, Value>,
        }

        let auth_data: AuthData = serde_json::from_value(serialized_auth_data.clone())?;

        trace!(?auth_data, "Verifying backup auth data");

        Ok(if let Some(signatures) = auth_data.signatures.get(self.store.user_id()) {
            for device_key_id in signatures.keys() {
                if device_key_id.algorithm() == DeviceKeyAlgorithm::Ed25519 {
                    if device_key_id.device_id() == self.account.device_id() {
                        let result = self.account.is_signed(&mut serialized_auth_data);

                        trace!(?result, "Checking auth data signature of our own device");

                        if result.is_ok() {
                            return Ok(true);
                        }
                    } else {
                        let device = self
                            .store
                            .get_device(self.store.user_id(), device_key_id.device_id())
                            .await?;

                        trace!(
                            device_id = device_key_id.device_id().as_str(),
                            "Checking backup auth data for device"
                        );

                        if let Some(device) = device {
                            if device.verified()
                                && device.is_signed_by_device(&mut serialized_auth_data).is_ok()
                            {
                                return Ok(true);
                            }
                        } else {
                            trace!(
                                device_id = device_key_id.device_id().as_str(),
                                "Device not found, can't check signature"
                            );
                        }
                    }
                }
            }

            false
        } else {
            false
        })
    }
/// Verify some backup auth data that we downloaded from the server.
///
/// The auth data should be fetched from the server using the
/// [`/room_keys/version`] endpoint.
///
/// Ruma models this using the [`BackupAlgorithm`] struct, but care needs to
/// be taken if that struct is used. Some clients might use unspecced fields
/// and the given Ruma struct will lose the unspecced fields after a
/// serialization cycle.
///
/// [`BackupAlgorithm`]: ruma::api::client::r0::backup::BackupAlgorithm
/// [`/room_keys/version`]: https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3room_keysversion
Verify some backup auth data that we downloaded from the server.
The auth data should be fetched from the server using the
[`/room_keys/version`] endpoint.

Ruma models this using the [`BackupAlgorithm`] struct, but care needs to
be taken if that struct is used. Some clients might use unspecced fields
and the given Ruma struct will lose the unspecced fields after a
serialization cycle.


Verify some backup auth data that we downloaded from the server . The auth data should be fetched from the server using the [ ` / room_keys / version ` ] endpoint . Ruma models this using the [ ` BackupAlgorithm ` ] struct but care needs to be taken if that struct is used . Some clients might use unspecced fields and the given Ruma struct will lose the unspecced fields after a serialization cycle .
pub async fn verify_backup(
        &self,
        mut serialized_auth_data: Value,
    ) -> Result<bool, CryptoStoreError> {
        #[derive(Debug, Serialize, Deserialize)]
        struct AuthData {
            public_key: String,
            #[serde(default)]
            signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
            #[serde(flatten)]
            extra: BTreeMap<String, Value>,
        }
        let auth_data: AuthData = serde_json::from_value(serialized_auth_data.clone())?;
        trace!(?auth_data, "Verifying backup auth data");
        Ok(if let Some(signatures) = auth_data.signatures.get(self.store.user_id()) {
            for device_key_id in signatures.keys() {
                if device_key_id.algorithm() == DeviceKeyAlgorithm::Ed25519 {
                    if device_key_id.device_id() == self.account.device_id() {
                        let result = self.account.is_signed(&mut serialized_auth_data);
                        trace!(?result, "Checking auth data signature of our own device");
                        if result.is_ok() {
                            return Ok(true);
                        }
                    } else {
                        let device = self
                            .store
                            .get_device(self.store.user_id(), device_key_id.device_id())
                            .await?;
                        trace!(
                            device_id = device_key_id.device_id().as_str(),
                            "Checking backup auth data for device"
                        );
                        if let Some(device) = device {
                            if device.verified()
                                && device.is_signed_by_device(&mut serialized_auth_data).is_ok()
                            {
                                return Ok(true);
                            }
                        } else {
                            trace!(
                                device_id = device_key_id.device_id().as_str(),
                                "Device not found, can't check signature"
                            );
                        }
                    }
                }
            }
            false
        } else {
            false
        })
    }
pub async fn verify_backup ( & self , mut serialized_auth_data : Value , ) -> Result < bool , CryptoStoreError > { # [ derive ( Debug Serialize Deserialize ) ] struct AuthData { public_key : String , # [ serde ( default ) ] signatures : BTreeMap < UserId , BTreeMap < DeviceKeyId , String > > , # [ serde ( flatten ) ] extra : BTreeMap < String , Value > , } let auth_data : AuthData = serde_json :: from_value ( serialized_auth_data . clone ( ) ) ? ; trace ! ( auth_data " " ) ; Ok ( if let Some ( signatures ) = auth_data . signatures . get ( self . store . user_id ( ) ) { for device_key_id in signatures . keys ( ) { if device_key_id . algorithm ( ) == DeviceKeyAlgorithm :: Ed25519 { if device_key_id . device_id ( ) == self . account . device_id ( ) { let result = self . account . is_signed ( & mut serialized_auth_data ) ; trace ! ( result " " ) ; if result . is_ok ( ) { return Ok ( true ) ; } } else { let device = self . store . get_device ( self . store . user_id ( ) , device_key_id . device_id ( ) ) . await ? ; trace ! ( device_id device_key_id device_id ( ) as_str ( ) " " ) ; if let Some ( device ) = device { if device . verified ( ) && device . is_signed_by_device ( & mut serialized_auth_data ) . is_ok ( ) { return Ok ( true ) ; } } else { trace ! ( device_id device_key_id device_id ( ) as_str ( ) " " ) ; } } } } false } else { false } ) }
Verify some backup auth data that we downloaded from the server.
Verify some backup auth data that we downloaded from the server .
&self
serialized_auth_data
Value
&self
serialized_auth_data
Value