pub fn add<C>(&mut self, cert: C, cur_time: Duration) -> Result<(), String>
    where
        C: Borrow<Certificate>,
    {
        let roots: Vec<PublicKey> = self.root_weights.keys().cloned().map(Into::into).collect();
        // Check that certificate is valid and converges to one of the known roots
        Certificate::verify(cert.borrow(), roots.as_slice(), cur_time)?;

        let mut chain = cert.borrow().chain.iter();
        let root_trust = chain.next().ok_or("empty chain")?;
        let root_pk: PublicKeyHashable = root_trust.issued_for.clone().into();

        // Insert new TrustNode for this root_pk if there wasn't one
        if self.nodes.get_mut(&root_pk).is_none() {
            let mut trust_node = TrustNode::new(root_trust.issued_for.clone(), cur_time);
            let root_auth = Auth {
                trust: root_trust.clone(),
                issued_by: root_trust.issued_for.clone(),
            };
            trust_node.update_auth(root_auth);
            self.nodes.insert(root_pk, trust_node);
        }

        // Insert remaining trusts to the graph
        let mut previous_trust = root_trust;
        for trust in chain {
            let pk = trust.issued_for.clone().into();

            let auth = Auth {
                trust: trust.clone(),
                issued_by: previous_trust.issued_for.clone(),
            };

            match self.nodes.get_mut(&pk) {
                Some(trust_node) => {
                    trust_node.update_auth(auth);
                }
                None => {
                    let mut trust_node = TrustNode::new(root_trust.issued_for.clone(), cur_time);
                    trust_node.update_auth(auth);
                    self.nodes.insert(pk, trust_node);
                }
            }

            previous_trust = trust;
        }

        Ok(())
    }
// TODO: remove cur_time from api, leave it for tests only
/// Certificate is a chain of trusts, add this chain to graph
remove cur_time from api, leave it for tests only
Certificate is a chain of trusts, add this chain to graph
remove cur_time from api leave it for tests only Certificate is a chain of trusts add this chain to graph
pub fn add<C>(&mut self, cert: C, cur_time: Duration) -> Result<(), String>
    where
        C: Borrow<Certificate>,
    {
        let roots: Vec<PublicKey> = self.root_weights.keys().cloned().map(Into::into).collect();
        // Check that certificate is valid and converges to one of the known roots
        Certificate::verify(cert.borrow(), roots.as_slice(), cur_time)?;
        let mut chain = cert.borrow().chain.iter();
        let root_trust = chain.next().ok_or("empty chain")?;
        let root_pk: PublicKeyHashable = root_trust.issued_for.clone().into();
        // Insert new TrustNode for this root_pk if there wasn't one
        if self.nodes.get_mut(&root_pk).is_none() {
            let mut trust_node = TrustNode::new(root_trust.issued_for.clone(), cur_time);
            let root_auth = Auth {
                trust: root_trust.clone(),
                issued_by: root_trust.issued_for.clone(),
            };
            trust_node.update_auth(root_auth);
            self.nodes.insert(root_pk, trust_node);
        }
        // Insert remaining trusts to the graph
        let mut previous_trust = root_trust;
        for trust in chain {
            let pk = trust.issued_for.clone().into();
            let auth = Auth {
                trust: trust.clone(),
                issued_by: previous_trust.issued_for.clone(),
            };
            match self.nodes.get_mut(&pk) {
                Some(trust_node) => {
                    trust_node.update_auth(auth);
                }
                None => {
                    let mut trust_node = TrustNode::new(root_trust.issued_for.clone(), cur_time);
                    trust_node.update_auth(auth);
                    self.nodes.insert(pk, trust_node);
                }
            }
            previous_trust = trust;
        }
        Ok(())
    }
pub fn add < C > ( & mut self , cert : C , cur_time : Duration ) -> Result < ( ) , String > where C : Borrow < Certificate > , { let roots : Vec < PublicKey > = self . root_weights . keys ( ) . cloned ( ) . map ( Into :: into ) . collect ( ) ; // Check that certificate is valid and converges to one of the known roots Certificate :: verify ( cert . borrow ( ) , roots . as_slice ( ) , cur_time ) ? ; let mut chain = cert . borrow ( ) . chain . iter ( ) ; let root_trust = chain . next ( ) . ok_or ( " " ) ? ; let root_pk : PublicKeyHashable = root_trust . issued_for . clone ( ) . into ( ) ; // Insert new TrustNode for this root_pk if there wasn't one if self . nodes . get_mut ( & root_pk ) . is_none ( ) { let mut trust_node = TrustNode :: new ( root_trust . issued_for . clone ( ) , cur_time ) ; let root_auth = Auth { trust : root_trust . clone ( ) , issued_by : root_trust . issued_for . clone ( ) , } ; trust_node . update_auth ( root_auth ) ; self . nodes . insert ( root_pk , trust_node ) ; } // Insert remaining trusts to the graph let mut previous_trust = root_trust ; for trust in chain { let pk = trust . issued_for . clone ( ) . into ( ) ; let auth = Auth { trust : trust . clone ( ) , issued_by : previous_trust . issued_for . clone ( ) , } ; match self . nodes . get_mut ( & pk ) { Some ( trust_node ) => { trust_node . update_auth ( auth ) ; } None => { let mut trust_node = TrustNode :: new ( root_trust . issued_for . clone ( ) , cur_time ) ; trust_node . update_auth ( auth ) ; self . nodes . insert ( pk , trust_node ) ; } } previous_trust = trust ; } Ok ( ( ) ) }
TODO: remove cur_time from api, leave it for tests only
Certificate is a chain of trusts, add this chain to graph
TODO : remove cur_time from api leave it for tests only Certificate is a chain of trusts add this chain to graph
&mut self
cert
C
cur_time
Duration