line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of PerlIO-via-GnuPG |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is Copyright (c) 2013 by Chris Weyl. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software, licensed under: |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# The GNU Lesser General Public License, Version 2.1, February 1999 |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
package PerlIO::via::GnuPG; |
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:RSRCHBOY'; |
12
|
|
|
|
|
|
|
# git description: 0.005-1-gdb3e32f |
13
|
|
|
|
|
|
|
$PerlIO::via::GnuPG::VERSION = '0.006'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# ABSTRACT: Layer to try to decrypt on read |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# required for how we're registering a warnings category |
18
|
1
|
|
|
1
|
|
22227
|
use v5.14; |
|
1
|
|
|
|
|
6
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
21
|
1
|
|
|
1
|
|
12
|
use warnings::register qw{ unencrypted }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9664
|
|
22
|
|
|
|
|
|
|
#use warnings::register; |
23
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
508
|
|
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
5049
|
use autodie 2.25; |
|
1
|
|
|
|
|
17570
|
|
|
1
|
|
|
|
|
6
|
|
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
7853
|
use IPC::Open3 'open3'; |
|
1
|
|
|
|
|
4216
|
|
|
1
|
|
|
|
|
51
|
|
28
|
1
|
|
|
1
|
|
7
|
use Symbol 'gensym'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
29
|
1
|
|
|
1
|
|
769
|
use List::AllUtils 'part'; |
|
1
|
|
|
|
|
15846
|
|
|
1
|
|
|
|
|
576
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# gpg --decrypt -q --status-file aksdja --no-tty |
32
|
|
|
|
|
|
|
# gpg --decrypt -q --status-file aksdja --no-tty .pause.gpg |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub PUSHED { |
35
|
3
|
|
|
3
|
0
|
12344
|
my ($class, $mode) = @_; |
36
|
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
193
|
return bless { }, $class; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
0
|
|
0
|
sub _passthrough_unencrypted { 0 } |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub FILL { |
43
|
9
|
|
|
9
|
0
|
64
|
my ($self, $fh) = @_; |
44
|
|
|
|
|
|
|
|
45
|
6
|
|
|
|
|
66
|
return shift @{ $self->{buffer} } |
46
|
9
|
100
|
|
|
|
39
|
if exists $self->{buffer}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
### pull in all of fh and try to decrypt it... |
49
|
3
|
|
|
|
|
6
|
my $maybe_encrypted = do { local $/; <$fh> }; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
63
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
### $maybe_encrypted |
52
|
3
|
|
|
|
|
23
|
my ($in, $out, $error) = (gensym, gensym, gensym); |
53
|
3
|
|
|
|
|
99
|
my $run = 'gpg -qd --no-tty --command-fd 0'; |
54
|
3
|
|
|
|
|
18
|
my $pid = open3($in, $out, $error, $run); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
### $pid |
57
|
3
|
|
|
|
|
20841
|
print $in $maybe_encrypted; |
58
|
3
|
|
|
|
|
46
|
close $in; |
59
|
3
|
|
|
|
|
64004
|
my @output = <$out>; |
60
|
3
|
|
|
|
|
142
|
my @errors = <$error>; |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
88
|
waitpid $pid, 0; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
### @output |
65
|
|
|
|
|
|
|
### @errors |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
### filter warnings out... |
68
|
3
|
|
|
|
|
19
|
chomp @errors; |
69
|
3
|
100
|
|
5
|
|
87
|
my ($errors, $warnings) = map { $_ || [] } part { /WARNING:/ ? 1 : 0 } @errors; |
|
6
|
100
|
|
|
|
54
|
|
|
5
|
|
|
|
|
74
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
### $warnings |
72
|
3
|
50
|
33
|
|
|
1218
|
warnings::warnif(@$warnings) |
73
|
|
|
|
|
|
|
if !!$warnings && @$warnings; |
74
|
|
|
|
|
|
|
|
75
|
3
|
100
|
66
|
|
|
594
|
if (!!$errors && @$errors) { |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
6
|
my $not_encrypted = scalar grep { /no valid OpenPGP data found/ } @$errors; |
|
2
|
|
|
|
|
17
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
### $not_encrypted |
80
|
|
|
|
|
|
|
### passthrough: $self->_passthrough_unencrypted |
81
|
1
|
50
|
|
|
|
7
|
if ($not_encrypted) { |
82
|
|
|
|
|
|
|
|
83
|
1
|
50
|
|
|
|
16
|
if ($self->_passthrough_unencrypted) { |
84
|
1
|
|
|
|
|
53
|
warnings::warnif( |
85
|
|
|
|
|
|
|
'PerlIO::via::GnuPG::unencrypted', |
86
|
|
|
|
|
|
|
'File does not appear to be encrypted!', |
87
|
|
|
|
|
|
|
); |
88
|
1
|
|
|
|
|
5
|
@output = ($maybe_encrypted); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
0
|
|
|
|
|
0
|
die "File does not appear to be encrypted!"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# "@errors" here is intentional -- show the warnings, too |
97
|
0
|
|
|
|
|
0
|
die "Errors while attempting decryption: @errors"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
3
|
|
|
|
|
22
|
$self->{buffer} = [ @output ]; |
102
|
3
|
|
|
|
|
6
|
return shift @{ $self->{buffer} }; |
|
3
|
|
|
|
|
160
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
!!42; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |