From f73054fa820773094ac663e87fbf96a59eb1dd3e Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Sat, 28 Sep 2019 17:30:44 +0200 Subject: openpgp: Collect statistics on algorithm preferences. --- openpgp/examples/statistics.rs | 109 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) (limited to 'openpgp/examples/statistics.rs') diff --git a/openpgp/examples/statistics.rs b/openpgp/examples/statistics.rs index b90ae7a0..6311f63e 100644 --- a/openpgp/examples/statistics.rs +++ b/openpgp/examples/statistics.rs @@ -50,6 +50,14 @@ fn main() { // Various SubpacketValue-related counters. let mut key_flags: HashMap = Default::default(); + let mut p_sym: HashMap, usize> = + Default::default(); + let mut p_hashes: HashMap, usize> = + Default::default(); + let mut p_comp: HashMap, usize> = + Default::default(); + let mut p_aead: HashMap, usize> = + Default::default(); // Per-TPK statistics. let mut tpk_count = 0; @@ -132,6 +140,34 @@ fn main() { } else { key_flags.insert(k.clone(), 1); }, + SubpacketValue::PreferredSymmetricAlgorithms(a) + => + if let Some(count) = p_sym.get_mut(&a) { + *count += 1; + } else { + p_sym.insert(a.clone(), 1); + }, + SubpacketValue::PreferredHashAlgorithms(a) + => + if let Some(count) = p_hashes.get_mut(&a) { + *count += 1; + } else { + p_hashes.insert(a.clone(), 1); + }, + SubpacketValue::PreferredCompressionAlgorithms(a) + => + if let Some(count) = p_comp.get_mut(&a) { + *count += 1; + } else { + p_comp.insert(a.clone(), 1); + }, + SubpacketValue::PreferredAEADAlgorithms(a) + => + if let Some(count) = p_aead.get_mut(&a) { + *count += 1; + } else { + p_aead.insert(a.clone(), 1); + }, _ => (), } } @@ -298,6 +334,79 @@ fn main() { } } + if p_sym.len() > 0 { + println!(); + println!("# PreferredSymmetricAlgorithms statistics"); + println!(); + println!("{:>70} {:>9}", "", "count",); + println!("----------------------------------------\ + ----------------------------------------"); + + // Sort by the number of occurrences. + let mut preferences = p_sym.iter().map(|(a, n)| { + let a = format!("{:?}", a); + (a[1..a.len()-1].to_string(), n) + }).collect::>(); + preferences.sort_unstable_by(|a, b| b.1.cmp(&a.1)); + for (a, n) in preferences { + println!("{:>70} {:>9}", a, n); + } + } + + if p_hashes.len() > 0 { + println!(); + println!("# PreferredHashlgorithms statistics"); + println!(); + println!("{:>70} {:>9}", "", "count",); + println!("----------------------------------------\ + ----------------------------------------"); + + // Sort by the number of occurrences. + let mut preferences = p_hashes.iter().map(|(a, n)| { + let a = format!("{:?}", a); + (a[1..a.len()-1].to_string(), n) + }).collect::>(); + preferences.sort_unstable_by(|a, b| b.1.cmp(&a.1)); + for (a, n) in preferences { + let a = format!("{:?}", a); + println!("{:>70} {:>9}", &a[1..a.len()-1], n); + } + } + + if p_comp.len() > 0 { + println!(); + println!("# PreferredCompressionAlgorithms statistics"); + println!(); + println!("{:>70} {:>9}", "", "count",); + println!("----------------------------------------\ + ----------------------------------------"); + + // Sort by the number of occurrences. + let mut preferences = p_comp.iter().map(|(a, n)| { + let a = format!("{:?}", a); + (a[1..a.len()-1].to_string(), n) + }).collect::>(); + preferences.sort_unstable_by(|a, b| b.1.cmp(&a.1)); + for (a, n) in preferences { + let a = format!("{:?}", a); + println!("{:>70} {:>9}", &a[1..a.len()-1], n); + } + } + + if p_aead.len() > 0 { + println!(); + println!("# PreferredAEADAlgorithms statistics"); + println!(); + println!("{:>70} {:>9}", "", "count",); + println!("----------------------------------------\ + ----------------------------------------"); + + for (a, n) in p_aead.iter() { + let a = format!("{:?}", a); + println!("{:>70} {:>9}", &a[1..a.len()-1], n); + } + } + if ua_invalid_count > 0 || ua_image_count.iter().any(|c| *c > 0) || ua_unknown_count.iter().any(|c| *c > 0) -- cgit v1.2.3