diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-03-18 14:44:11 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-03-18 15:12:01 +0100 |
commit | ad70e67a02d30a2605e715a77338c40b03b1d99e (patch) | |
tree | 6f03c7f07e24f16a0f6a19443ecd1a13658b8387 /openpgp | |
parent | 97cdc3062d88401dcc849c3f4e093a4f7b1b1226 (diff) |
openpgp: Add a new example.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/examples/web-of-trust.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/openpgp/examples/web-of-trust.rs b/openpgp/examples/web-of-trust.rs new file mode 100644 index 00000000..ee760b44 --- /dev/null +++ b/openpgp/examples/web-of-trust.rs @@ -0,0 +1,59 @@ +/// Extracts the Web-Of-Trust, i.e. the certification relation, from +/// SKS packet dump using the openpgp crate, Sequoia's low-level API. +/// +/// Note that to achieve reasonable performance, you need to compile +/// Sequoia and this program with optimizations: +/// +/// % cargo run -p sequoia-openpgp --example web-of-trust --release \ +/// -- <packet-dump> [<packet-dump> ...] + +use std::env; + +extern crate sequoia_openpgp as openpgp; +use openpgp::tpk::TPKParser; +use openpgp::parse::Parse; + +fn main() { + let args: Vec<String> = env::args().collect(); + if args.len() < 2 { + panic!("Extracts the certification relation from OpenPGP packet dumps.\ + \n\nUsage: {} <packet-dump> [<packet-dump> ...]\n", args[0]); + } + + // The issuer refers to a (sub)key, but we want to use the primary + // keys as identifiers. But, because there are no tools besides + // Sequoia that support certification-capable subkeys, we will + // assume for now that the issuer is always a primary key. + + eprintln!("Format: certifier, user-id, key"); + + // For each input file, create a parser. + for input in &args[1..] { + eprintln!("Parsing {}...", input); + let mut parser = TPKParser::from_file(input) + .expect("Failed to create reader"); + + for tpk in parser { + match tpk { + Ok(tpk) => { + let keyid = tpk.fingerprint().to_keyid(); + for uidb in tpk.userids() { + for tps in uidb.certifications() { + if let Some(issuer) = tps.get_issuer() { + println!("{}, {:?}, {}", + issuer.as_u64().unwrap(), + String::from_utf8_lossy( + uidb.userid().userid()), + keyid.as_u64().unwrap()); + } else { + eprintln!("No issuer!?"); + } + } + } + }, + Err(e) => + eprintln!("Parsing TPK failed: {}", e), + } + } + } +} |