pub fn verify(
        cert: &Certificate,
        trusted_roots: &[PublicKey],
        cur_time: Duration,
    ) -> Result<(), String> {
        let chain = &cert.chain;

        if chain.is_empty() {
            return Err("The certificate must have at least 1 trust".to_string());
        }

        // check root trust and its existence in trusted roots list
        let root = &chain[0];
        Trust::verify(root, &root.issued_for, cur_time)
            .map_err(|e| format!("Root trust did not pass verification: {}", e))?;
        if !trusted_roots.contains(&root.issued_for) {
            return Err("Certificate does not contain a trusted root.".to_string());
        }

        // check if every element in a chain is not expired and has the correct signature
        for trust_id in (1..chain.len()).rev() {
            let trust = &chain[trust_id];

            let trust_giver = &chain[trust_id - 1];

            Trust::verify(trust, &trust_giver.issued_for, cur_time).map_err(|e| {
                format!(
                    "Trust {} in chain did not pass verification: {}",
                    trust_id, e
                )
            })?;
        }

        Ok(())
    }
/// Verifies that a certificate is valid and you trust to this certificate.
Verifies that a certificate is valid and you trust to this certificate.
Verifies that a certificate is valid and you trust to this certificate .
pub fn verify(
        cert: &Certificate,
        trusted_roots: &[PublicKey],
        cur_time: Duration,
    ) -> Result<(), String> {
        let chain = &cert.chain;
        if chain.is_empty() {
            return Err("The certificate must have at least 1 trust".to_string());
        }
        // check root trust and its existence in trusted roots list
        let root = &chain[0];
        Trust::verify(root, &root.issued_for, cur_time)
            .map_err(|e| format!("Root trust did not pass verification: {}", e))?;
        if !trusted_roots.contains(&root.issued_for) {
            return Err("Certificate does not contain a trusted root.".to_string());
        }
        // check if every element in a chain is not expired and has the correct signature
        for trust_id in (1..chain.len()).rev() {
            let trust = &chain[trust_id];
            let trust_giver = &chain[trust_id - 1];
            Trust::verify(trust, &trust_giver.issued_for, cur_time).map_err(|e| {
                format!(
                    "Trust {} in chain did not pass verification: {}",
                    trust_id, e
                )
            })?;
        }
        Ok(())
    }
pub fn verify ( cert : & Certificate , trusted_roots : & [ PublicKey ] , cur_time : Duration , ) -> Result < ( ) , String > { let chain = & cert . chain ; if chain . is_empty ( ) { return Err ( " " . to_string ( ) ) ; } // check root trust and its existence in trusted roots list let root = & chain [ 0 ] ; Trust :: verify ( root , & root . issued_for , cur_time ) . map_err ( | e | format ! ( " " e ) ) ? ; if ! trusted_roots . contains ( & root . issued_for ) { return Err ( " " . to_string ( ) ) ; } // check if every element in a chain is not expired and has the correct signature for trust_id in ( 1 .. chain . len ( ) ) . rev ( ) { let trust = & chain [ trust_id ] ; let trust_giver = & chain [ trust_id - 1 ] ; Trust :: verify ( trust , & trust_giver . issued_for , cur_time ) . map_err ( | e | { format ! ( " " trust_id e ) } ) ? ; } Ok ( ( ) ) }
Verifies that a certificate is valid and you trust to this certificate.
Verifies that a certificate is valid and you trust to this certificate .
cert
&Certificate
trusted_roots
&[PublicKey]
cur_time
Duration