diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-09-28 17:30:44 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-09-29 23:21:11 +0200 |
commit | f73054fa820773094ac663e87fbf96a59eb1dd3e (patch) | |
tree | 9eaa6ffe292fd54edca4af80bc15f3024b81fa61 /openpgp/examples/statistics.rs | |
parent | c6fc578850f5eab0b15d3ac824ec4ca24b2ba56f (diff) |
openpgp: Collect statistics on algorithm preferences.
Diffstat (limited to 'openpgp/examples/statistics.rs')
-rw-r--r-- | openpgp/examples/statistics.rs | 109 |
1 files changed, 109 insertions, 0 deletions
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<KeyFlags, usize> = Default::default(); + let mut p_sym: HashMap<Vec<SymmetricAlgorithm>, usize> = + Default::default(); + let mut p_hashes: HashMap<Vec<HashAlgorithm>, usize> = + Default::default(); + let mut p_comp: HashMap<Vec<CompressionAlgorithm>, usize> = + Default::default(); + let mut p_aead: HashMap<Vec<AEADAlgorithm>, 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::<Vec<_>>(); + 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::<Vec<_>>(); + 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::<Vec<_>>(); + 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) |