fn initialize_sender_ratchets(
        &mut self,
        ciphersuite: &Ciphersuite,
        backend: &impl OpenMlsCryptoProvider,
        index: LeafIndex,
    ) -> Result<(), SecretTreeError> {
        log::trace!(
            "Initializing sender ratchets for {:?} with {}",
            index,
            ciphersuite
        );
        if index >= self.size {
            log::error!("Index is larger than the tree size.");
            return Err(SecretTreeError::IndexOutOfBounds);
        }
        // Check if SenderRatchets are already initialized
        if self
            .ratchet_opt(index, SecretType::HandshakeSecret)
            .expect("Index out of bounds.")
            .is_some()
            && self
                .ratchet_opt(index, SecretType::ApplicationSecret)
                .expect("Index out of bounds.")
                .is_some()
        {
            log::trace!("The sender ratchets are initialized already.");
            return Ok(());
        }
        // Calculate direct path
        let index_in_tree = NodeIndex::from(index);
        let mut dir_path = vec![index_in_tree];
        dir_path.extend(
            leaf_direct_path(index, self.size)
                .expect("initialize_sender_ratchets: Error while computing direct path."),
        );
        log::trace!("Direct path for leaf {:?}: {:?}", index, dir_path);
        let mut empty_nodes: Vec<NodeIndex> = vec![];
        for n in dir_path {
            empty_nodes.push(n);
            if self.nodes[n.as_usize()].is_some() {
                break;
            }
        }
        // Remove leaf and invert direct path
        empty_nodes.remove(0);
        empty_nodes.reverse();
        // Find empty nodes
        for n in empty_nodes {
            self.derive_down(ciphersuite, backend, n);
        }
        // Calculate node secret and initialize SenderRatchets
        let node_secret = &self.nodes[index_in_tree.as_usize()]
            .as_ref()
            .unwrap()
            .secret;
        let handshake_ratchet_secret = derive_tree_secret(
            node_secret,
            "handshake",
            index_in_tree.as_u32(),
            0,
            ciphersuite.hash_length(),
            backend,
        );
        let handshake_sender_ratchet = SenderRatchet::new(index, &handshake_ratchet_secret);
        self.handshake_sender_ratchets[index.as_usize()] = Some(handshake_sender_ratchet);
        let application_ratchet_secret = derive_tree_secret(
            node_secret,
            "application",
            index_in_tree.as_u32(),
            0,
            ciphersuite.hash_length(),
            backend,
        );
        let application_sender_ratchet = SenderRatchet::new(index, &application_ratchet_secret);
        self.application_sender_ratchets[index.as_usize()] = Some(application_sender_ratchet);
        // Delete leaf node
        self.nodes[index_in_tree.as_usize()] = None;
        Ok(())
    }
/// Initializes a specific SenderRatchet pair for a given index by
/// calculating and deleting the appropriate values in the SecretTree
Initializes a specific SenderRatchet pair for a given index by
calculating and deleting the appropriate values in the SecretTree
Initializes a specific SenderRatchet pair for a given index by calculating and deleting the appropriate values in the SecretTree
fn initialize_sender_ratchets(
        &mut self,
        ciphersuite: &Ciphersuite,
        backend: &impl OpenMlsCryptoProvider,
        index: LeafIndex,
    ) -> Result<(), SecretTreeError> {
        log::trace!(
            "Initializing sender ratchets for {:?} with {}",
            index,
            ciphersuite
        );
        if index >= self.size {
            log::error!("Index is larger than the tree size.");
            return Err(SecretTreeError::IndexOutOfBounds);
        }
        // Check if SenderRatchets are already initialized
        if self
            .ratchet_opt(index, SecretType::HandshakeSecret)
            .expect("Index out of bounds.")
            .is_some()
            && self
                .ratchet_opt(index, SecretType::ApplicationSecret)
                .expect("Index out of bounds.")
                .is_some()
        {
            log::trace!("The sender ratchets are initialized already.");
            return Ok(());
        }
        // Calculate direct path
        let index_in_tree = NodeIndex::from(index);
        let mut dir_path = vec![index_in_tree];
        dir_path.extend(
            leaf_direct_path(index, self.size)
                .expect("initialize_sender_ratchets: Error while computing direct path."),
        );
        log::trace!("Direct path for leaf {:?}: {:?}", index, dir_path);
        let mut empty_nodes: Vec<NodeIndex> = vec![];
        for n in dir_path {
            empty_nodes.push(n);
            if self.nodes[n.as_usize()].is_some() {
                break;
            }
        }
        // Remove leaf and invert direct path
        empty_nodes.remove(0);
        empty_nodes.reverse();
        // Find empty nodes
        for n in empty_nodes {
            self.derive_down(ciphersuite, backend, n);
        }
        // Calculate node secret and initialize SenderRatchets
        let node_secret = &self.nodes[index_in_tree.as_usize()]
            .as_ref()
            .unwrap()
            .secret;
        let handshake_ratchet_secret = derive_tree_secret(
            node_secret,
            "handshake",
            index_in_tree.as_u32(),
            0,
            ciphersuite.hash_length(),
            backend,
        );
        let handshake_sender_ratchet = SenderRatchet::new(index, &handshake_ratchet_secret);
        self.handshake_sender_ratchets[index.as_usize()] = Some(handshake_sender_ratchet);
        let application_ratchet_secret = derive_tree_secret(
            node_secret,
            "application",
            index_in_tree.as_u32(),
            0,
            ciphersuite.hash_length(),
            backend,
        );
        let application_sender_ratchet = SenderRatchet::new(index, &application_ratchet_secret);
        self.application_sender_ratchets[index.as_usize()] = Some(application_sender_ratchet);
        // Delete leaf node
        self.nodes[index_in_tree.as_usize()] = None;
        Ok(())
    }
fn initialize_sender_ratchets ( & mut self , ciphersuite : & Ciphersuite , backend : & impl OpenMlsCryptoProvider , index : LeafIndex , ) -> Result < ( ) , SecretTreeError > { log :: trace ! ( " " index ciphersuite ) ; if index >= self . size { log :: error ! ( " " ) ; return Err ( SecretTreeError :: IndexOutOfBounds ) ; } // Check if SenderRatchets are already initialized if self . ratchet_opt ( index , SecretType :: HandshakeSecret ) . expect ( " " ) . is_some ( ) && self . ratchet_opt ( index , SecretType :: ApplicationSecret ) . expect ( " " ) . is_some ( ) { log :: trace ! ( " " ) ; return Ok ( ( ) ) ; } // Calculate direct path let index_in_tree = NodeIndex :: from ( index ) ; let mut dir_path = vec ! [ index_in_tree ] ; dir_path . extend ( leaf_direct_path ( index , self . size ) . expect ( " " ) , ) ; log :: trace ! ( " " index dir_path ) ; let mut empty_nodes : Vec < NodeIndex > = vec ! [ ] ; for n in dir_path { empty_nodes . push ( n ) ; if self . nodes [ n . as_usize ( ) ] . is_some ( ) { break ; } } // Remove leaf and invert direct path empty_nodes . remove ( 0 ) ; empty_nodes . reverse ( ) ; // Find empty nodes for n in empty_nodes { self . derive_down ( ciphersuite , backend , n ) ; } // Calculate node secret and initialize SenderRatchets let node_secret = & self . nodes [ index_in_tree . as_usize ( ) ] . as_ref ( ) . unwrap ( ) . secret ; let handshake_ratchet_secret = derive_tree_secret ( node_secret , " " , index_in_tree . as_u32 ( ) , 0 , ciphersuite . hash_length ( ) , backend , ) ; let handshake_sender_ratchet = SenderRatchet :: new ( index , & handshake_ratchet_secret ) ; self . handshake_sender_ratchets [ index . as_usize ( ) ] = Some ( handshake_sender_ratchet ) ; let application_ratchet_secret = derive_tree_secret ( node_secret , " " , index_in_tree . as_u32 ( ) , 0 , ciphersuite . hash_length ( ) , backend , ) ; let application_sender_ratchet = SenderRatchet :: new ( index , & application_ratchet_secret ) ; self . application_sender_ratchets [ index . as_usize ( ) ] = Some ( application_sender_ratchet ) ; // Delete leaf node self . nodes [ index_in_tree . as_usize ( ) ] = None ; Ok ( ( ) ) }
Initializes a specific SenderRatchet pair for a given index by
calculating and deleting the appropriate values in the SecretTree
Initializes a specific SenderRatchet pair for a given index by calculating and deleting the appropriate values in the SecretTree
&mut self
ciphersuite
&Ciphersuite
backend
&impl OpenMlsCryptoProvider
index
LeafIndex
&mut self
ciphersuite
&Ciphersuite
backend
&impl OpenMlsCryptoProvider
index
LeafIndex