3 # gpg-key2ps: convert a PGP/GnuPG key into paper slips.
10 my $version = '$Rev$';
11 $version =~ s/\$Rev:\s*(\d+)\s*\$/$1/;
12 my $usage = "Usage: $0 [-p papersize] [-r revoked-style] keyid-or-name\n";
14 my $revokestyle="hide";
23 if ( $opts{r
} ) { $revokestyle = $opts{'r'}; }
24 if ( $opts{p
} ) { $ENV{'PAPERSIZE'} = $opts{'p'}; }
25 foreach (@ARGV) { $keyids .= $_ . " "; }
27 if ( $revokestyle !~ /^(grey|hide|note|show|strike)$/ ) {
28 print STDERR
"Unknown style \"$revokestyle\". Please use one of\n";
29 print STDERR
" grey - Print text in grey\n";
30 print STDERR
" hide - Don't show revoked uids\n";
31 print STDERR
" note - Add \"(revoked)\"\n";
32 print STDERR
" show - List revoked uids normally\n";
33 print STDERR
" strike - Strike through lines\n";
38 if ( -x
"/usr/bin/paperconf" ) {
49 if ( system( "gpg --fingerprint $keyids >/dev/null" ) != 0 ) {
50 print STDERR
"Key not found. Try 'gpg --list-keys'\n";
54 open(GPG
, "gpg --fingerprint --with-colons $keyids |");
58 %%BoundingBox: 0 0 $w $h
60 %%Creator: gpg-key2ps $version
62 print "%%CreationDate: " . scalar(localtime) . "\n";
72 /Times-Roman findfont 9 scalefont setfont
80 w 2 div 30 sub y 3 add lineto stroke
85 /condhline { hline } def
93 << 1 (R) 2 (r) 3 (s) 16 (g) 20 (G) 17 (D) >> exch get
99 50 y moveto (pub) show
100 70 y moveto show showAlgorithm (/) show show
108 70 y moveto (Key fingerprint = ) show show
113 50 y moveto (uid) show
120 if ( $revokestyle eq "grey" ) {
122 print " .5 setgray\n";
124 print " 0 setgray\n";
126 } elsif ( $revokestyle eq "hide" ) {
127 print "/revuid {} def\n";
128 } elsif ( $revokestyle eq "note" ) {
130 print " 50 y moveto (uid) show\n";
131 print " 200 y moveto show ([revoked]) show\n";
134 } elsif ( $revokestyle eq "show" ) {
135 print "/revuid { uid } def\n";
136 } elsif ( $revokestyle eq "strike" ) {
139 print " 45 y 9 add moveto h 2 div 45 sub y 18 add lineto stroke\n";
146 50 y moveto (sub) show
147 70 y moveto show showAlgorithm (/) show show
158 if ( /^(tru|uat):/ ) { next; }
159 if ( /^pub:/ ) { $numlines++; }
160 s/^pub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:([^:]*):[^:]*:[^:]*:.*/ ($5) ($4) ($3) $2 ($1) pub/;
161 if ( /^fpr:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ) {
164 $fpr =~ s/(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})/$1 $2 $3 $4 $5 $6 $7 $8 $9 $10/;
166 $fpr =~ s/(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})/$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16/g;
167 $_ = " ($fpr) fpr\n";
169 s/^uid:[^:r]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) uid/;
170 s/^uid:[^:r]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) uid/;
171 s/^uid:r[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) revuid/;
172 s/^sub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ ($4) ($3) $2 ($1) sbk/;
182 print "/numlines $numlines def\n";
184 /num w 16 sub 10 div numlines div def
190 0 0 h 2 div w rectclip
195 0 upper h 2 div upper h 2 div lower 0 lower 0 upper moveto lineto lineto lineto lineto stroke