File Coverage

blib/lib/App/Greple/pgp.pm
Criterion Covered Total %
statement 11 18 61.1
branch 0 6 0.0
condition 0 3 0.0
subroutine 4 6 66.6
pod 0 2 0.0
total 15 35 42.8


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             pgp - Greple module to handle PGP encrypted files
4              
5             =head1 SYNOPSIS
6              
7             greple -Mpgp pattern *.gpg
8              
9             greple -Mpgp --pgppass 'passphrase' pattern file.gpg
10              
11             =head1 DESCRIPTION
12              
13             Enables searching within PGP/GPG encrypted files. Files with
14             I<.pgp>, I<.gpg>, or I<.asc> extensions are automatically decrypted.
15             Passphrase is requested interactively once and cached for subsequent
16             files.
17              
18             =head1 REQUIREMENTS
19              
20             This module requires the B (GnuPG) command to be installed and
21             available in PATH.
22              
23             =head1 OPTIONS
24              
25             =over 7
26              
27             =item B<--pgppass> I
28              
29             Specify the PGP passphrase directly. B for security
30             reasons as the passphrase may be visible in process listings or shell
31             history. Use interactive input instead when possible.
32              
33             =back
34              
35             =head1 SECURITY NOTES
36              
37             =over 4
38              
39             =item *
40              
41             The passphrase is stored in memory during execution and cleared when
42             no longer needed.
43              
44             =item *
45              
46             Decrypted content is processed through pipes and not written to disk.
47              
48             =item *
49              
50             Avoid using B<--pgppass> option in scripts or command history.
51              
52             =back
53              
54             =head1 SEE ALSO
55              
56             L, L
57              
58             =cut
59              
60             package App::Greple::pgp;
61              
62 1     1   1076 use v5.24;
  1         3  
63 1     1   5 use warnings;
  1         1  
  1         36  
64 1     1   3 use Carp;
  1         1  
  1         44  
65              
66 1     1   4 use App::Greple::PgpDecryptor;
  1         10  
  1         136  
67              
68             my $pgp;
69             our $opt_pgppass;
70              
71             sub activate {
72 0     0 0   ($pgp = App::Greple::PgpDecryptor->new)
73             ->initialize({passphrase => $opt_pgppass});
74             }
75              
76             sub filter {
77 0 0   0 0   activate if not defined $pgp;
78 0           $pgp->reset;
79 0   0       my $pid = open(STDIN, '-|') // croak "process fork failed";
80 0 0         if ($pid == 0) {
81 0 0         exec $pgp->decrypt_command or die $!;
82             }
83 0           $pid;
84             }
85              
86             1;
87              
88             __DATA__