summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-03-18 14:44:11 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-03-18 15:12:01 +0100
commitad70e67a02d30a2605e715a77338c40b03b1d99e (patch)
tree6f03c7f07e24f16a0f6a19443ecd1a13658b8387 /openpgp
parent97cdc3062d88401dcc849c3f4e093a4f7b1b1226 (diff)
openpgp: Add a new example.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/examples/web-of-trust.rs59
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),
+ }
+ }
+ }
+}
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660