fn count_all()

in rust-create-cascade/src/main.rs [413:461]


fn count_all(
    revoked_dir: &Path,
    known_dir: &Path,
    reason_set: ReasonSet,
    output_csv_path: Option<&Path>,
) -> BlockStats {
    let mut counts: Vec<(OsString, BlockStats)> = list_issuer_file_pairs(revoked_dir, known_dir)
        .par_iter()
        .map(|pair| {
            let (issuer, revoked_file, known_file) = pair;
            let revoked_serials_and_reasons = revoked_file
                .as_ref()
                .map(|x| RevokedSerialAndReasonIterator::new(x, reason_set));
            let known_serials = KnownSerialIterator::new(known_file);
            (
                issuer.clone(),
                count(revoked_serials_and_reasons, known_serials),
            )
        })
        .collect();

    if let Some(output_csv_path) = output_csv_path {
        let mut output_csv = File::create(output_csv_path)
            .expect("could not open output file for reason code counts");
        writeln!(output_csv, "issuer_spki_hash,unspecified,key_compromise,privilege_withdrawn,affiliation_changed,superseded,cessation_of_operation,revoked_certificates,non_revoked_certificates").expect("could not write reason code count line");
        for (issuer, block_stats) in &counts {
            let reasons = &block_stats.reasons;
            writeln!(
                output_csv,
                "{issuer},{unspecified},{key_compromise},{privilege_withdrawn},{affiliation_changed},{superseded},{cessation},{revoked},{non_revoked}",
                issuer = issuer.to_str().unwrap(),
                unspecified = reasons.unspecified,
                key_compromise = reasons.key_compromise,
                privilege_withdrawn = reasons.privilege_withdrawn,
                affiliation_changed = reasons.affiliation_changed,
                superseded = reasons.superseded,
                cessation = reasons.cessation_of_operation,
                revoked = block_stats.exact_revoked_count,
                non_revoked = block_stats.approx_ok_count,
            )
            .expect("could not write reason code count line");
        }
    }
    counts
        .drain(..)
        .map(|x| x.1)
        .reduce(|a, b| a.merge(b))
        .unwrap_or_default()
}