Add gpglist
[pgp-tools.git] / gpglist / gpglist
1 #!/usr/bin/perl
2
3 # small script to show in an intuitive way who signed which of your user ids
4 #
5 # Copyright (c) 2004 Uli Martens <uli@youam.net>
6 # Copyright (c) 2005 Peter Palfrader <peter@palfrader.org>
7 # All rights reserved.
8 #
9 # Released under a BSD style license as given in http://www.debian.org/misc/bsd.license
10
11 use strict;
12 use warnings;
13
14 my $key=shift @ARGV;
15 if ( $key eq "" ) {
16 die
17 }
18
19 open SIGS, "gpg --fixed-list-mode --with-colons --list-sigs $key 2>/dev/null |"
20 or die "can't get gpg listing";
21
22 my $uid = "";
23 my @uids;
24 my %sigs;
25 my %rev;
26 my %ids;
27 my %unknownID;
28 my $longkey;
29 while (<SIGS>) {
30 if ( m/^uid:.:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:(.*):$/ ) {
31 $uid = $1;
32 push @uids, $1;
33 next;
34 }
35 if ( m/^sig:[^:]*:[^:]*:[^:]*:([0-9A-F]*):[^:]*:[^:]*:[^:]*:[^:]*:(.*):[^:]*:$/ ) {
36 $2 eq "[User id not found]" ? $unknownID{$1} = $1 : $ids{$2} = $1;
37 $sigs{$1}->{$uid} = "x" unless defined $sigs{$1}->{$uid};
38 next;
39 }
40 if ( m/^rev:[^:]*:[^:]*:[^:]*:([0-9A-F]*):[^:]*:[^:]*:[^:]*:[^:]*:(.*):[^:]*:$/ ) {
41 $rev{$uid} = "x" if ($longkey eq $1);
42 $sigs{$1}->{$uid} = "R";
43 next;
44 }
45 if ( m/^uat:.:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:(.*):$/ ) {
46 $uid = "Photo ID";
47 push @uids, $uid;
48 next;
49 }
50 if ( m/^pub:[^:]*:[^:]*:[^:]*:([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:(.*):$/ ) {
51 $longkey = $1;
52 next;
53 }
54 last if ( m/^(sub):/ );
55 next if ( m/^(tru):/ );
56 print STDERR "hi, i'm a bug. please report me to my owner";
57 die "input: $_, key: $key";
58 }
59 close SIGS;
60
61 my $n = scalar @uids -1;
62 for ( my $a=0; $a <= $n; $a++ ) {
63 printf "| " x ($a)
64 . "+--"
65 . "---" x ($n-$a)
66 . (defined $rev{$uids[$a]} ? "R" : " ")
67 . "%2i $uids[$a]\n", $a+1;
68 }
69
70 for ( my $a=0; $a <= $n; $a++ ) {
71 printf "%-2i ", $a+1;
72 }
73 print "\n";
74
75 for my $id (sort keys %ids) {
76 print((defined $sigs{$ids{$id}}->{$_} ? $sigs{$ids{$id}}->{$_} : " ") . " ") for (@uids);
77 print $ids{$id}." $id\n";
78 }
79 for my $id (sort keys %unknownID) {
80 print((defined $sigs{$id}->{$_} ? $sigs{$id}->{$_} : " ") . " ") for (@uids);
81 print "$id [User id not found]\n";
82 }