// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // Copyright by contributors to this project. // SPDX-License-Identifier: (Apache-2.0 OR MIT)
#[cfg(feature = "std")] use std::collections::HashSet;
#[cfg(not(feature = "std"))] use alloc::{vec, vec::Vec}; use tree_math::TreeIndex;
usesuper::node::{Node, NodeIndex}; usecrate::client::MlsError; usecrate::crypto::CipherSuiteProvider; usecrate::group::GroupContext; usecrate::iter::wrap_impl_iter; usecrate::tree_kem::math as tree_math; usecrate::tree_kem::{leaf_node_validator::LeafNodeValidator, TreeKemPublic}; use mls_rs_core::identity::IdentityProvider;
#[cfg(all(not(mls_build_async), feature = "rayon"))] use rayon::prelude::*;
#[cfg(mls_build_async)] use futures::{StreamExt, TryStreamExt};
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] asyncfn validate_tree_hash(&self, tree: &mut TreeKemPublic) -> Result<(), MlsError> { //Verify that the tree hash of the ratchet tree matches the tree_hash field in the GroupInfo. let tree_hash = tree.tree_hash(self.cipher_suite_provider).await?;
if tree_hash != self.expected_tree_hash { return Err(MlsError::TreeHashMismatch);
}
// For each leaf L, we search for the longest prefix P[1], P[2], ..., P[k] of the direct path of L // such that for each i=1..k, either L is in the unmerged leaves of P[i], or P[i] is blank. We will // then check that L is unmerged at each P[1], ..., P[k] and no other node. let leaf_count = tree.total_leaf_count();
for (index, _) in tree.nodes.non_empty_leaves() { letmut n = NodeIndex::from(index);
whilelet Some(ps) = n.parent_sibling(&leaf_count) { if tree.nodes.is_blank(ps.parent)? {
n = ps.parent; continue;
}
let parent_node = tree.nodes.borrow_as_parent(ps.parent)?;
if parent_node.unmerged_leaves.contains(&index) {
unmerged_sets[ps.parent as usize].retain(|i| i != &index);
n = ps.parent;
} else { break;
}
}
}
let unmerged_sets = unmerged_sets.iter().all(|set| set.is_empty());
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] asyncfn test_valid_tree() { for cipher_suite in TestCryptoProvider::all_supported_cipher_suites() { let cipher_suite_provider = test_cipher_suite_provider(cipher_suite);
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] asyncfn verify_unmerged_with_leaf_outside_tree() { letmut tree = get_test_tree_fig_12(TEST_CIPHER_SUITE).await;
// Add leaf E from the right subtree of the root to unmerged leaves of node 1 on the left
tree.nodes.borrow_as_parent_mut(1).unwrap().unmerged_leaves = vec![LeafIndex(4)];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.