summaryrefslogtreecommitdiffstats
path: root/openpgp/examples
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-09-28 15:40:58 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-09-29 23:21:11 +0200
commitc6fc578850f5eab0b15d3ac824ec4ca24b2ba56f (patch)
tree172a139e7e99becf826570be1e32926aa0d4c0aa /openpgp/examples
parente7d871a3463fabc56ce53cd2623496f7a8d7278a (diff)
openpgp: Collect KeyFlags statistics.
Diffstat (limited to 'openpgp/examples')
-rw-r--r--openpgp/examples/statistics.rs33
1 files changed, 32 insertions, 1 deletions
diff --git a/openpgp/examples/statistics.rs b/openpgp/examples/statistics.rs
index 6c940813..b90ae7a0 100644
--- a/openpgp/examples/statistics.rs
+++ b/openpgp/examples/statistics.rs
@@ -8,9 +8,10 @@
/// -- <packet-dump>
use std::env;
+use std::collections::HashMap;
extern crate sequoia_openpgp as openpgp;
use crate::openpgp::Packet;
-use crate::openpgp::constants::SignatureType;
+use crate::openpgp::constants::*;
use crate::openpgp::packet::{user_attribute, header::BodyLength, Tag};
use crate::openpgp::packet::signature::subpacket::SubpacketTag;
use crate::openpgp::parse::{Parse, PacketParserResult, PacketParser};
@@ -47,6 +48,9 @@ fn main() {
let mut signature_min = PerSignature::max();
let mut signature_max = PerSignature::min();
+ // Various SubpacketValue-related counters.
+ let mut key_flags: HashMap<KeyFlags, usize> = Default::default();
+
// Per-TPK statistics.
let mut tpk_count = 0;
let mut tpk = PerTPK::min();
@@ -119,6 +123,17 @@ fn main() {
if len > sigs_subpacket_tags_size_max[i] {
sigs_subpacket_tags_size_max[i] = len;
}
+
+ match sub.value {
+ SubpacketValue::Unknown(_) => unreachable!(),
+ SubpacketValue::KeyFlags(k) =>
+ if let Some(count) = key_flags.get_mut(&k) {
+ *count += 1;
+ } else {
+ key_flags.insert(k.clone(), 1);
+ },
+ _ => (),
+ }
}
}
@@ -267,6 +282,22 @@ fn main() {
}
}
+ if key_flags.len() > 0 {
+ println!();
+ println!("# KeyFlags statistics");
+ println!();
+ println!("{:>22} {:>9}", "", "count",);
+ println!("--------------------------------");
+
+ // Sort by the number of occurrences.
+ let mut kf = key_flags.iter().map(|(f, n)| (format!("{:?}", f), n))
+ .collect::<Vec<_>>();
+ kf.sort_unstable_by(|a, b| b.1.cmp(&a.1));
+ for (f, n) in kf.iter() {
+ println!("{:>22} {:>9}", f, n);
+ }
+ }
+
if ua_invalid_count > 0
|| ua_image_count.iter().any(|c| *c > 0)
|| ua_unknown_count.iter().any(|c| *c > 0)