pub async fn compute_condensed_mac<R: AsyncRead>(
    reader: R,
    size: u64,
    aes_key: &[u8; 16],
    aes_iv: &[u8; 8]
) -> Result<[u8; 8]>
Expand description

This function computes a full-coverage condensed MAC, in the exact same way that MEGA does it.

This allows to compute a condensed MAC for any arbitrary data and compare it to the ones of remote MEGA nodes.

Using these MACs is more accurate to assess file integrity than the sparse checksum method, but it is both more CPU and disk intensive to do so.

Here is an example of how to use this function:

use tokio_util::compat::TokioAsyncReadCompatExt;

let nodes = mega.fetch_own_nodes().await?;

let (remote_condensed_mac, key, iv) = {
    let node = nodes.get_node_by_path("/Root/some-remote-file.txt").unwrap();
    let condensed_mac = node.condensed_mac().unwrap();
    let key = node.aes_key();
    let iv = node.aes_iv().unwrap();
    (condensed_mac, key, iv)
};

let local_condensed_mac = {
    let file = tokio::fs::File::open("some-local-file.txt").await?;
    let size = file.metadata().await?.len();
    mega::compute_condensed_mac(file.compat(), size, key, iv).await?
};

if local_condensed_mac == *remote_condensed_mac {
    println!("OK ! (the MACs are identical)");
} else {
    println!("FAILED ! (the MACs differ)");
}