OpenPGP/Message.pm

filter: Statementstmt 98.3% 61 / 62 Branchbran 72.2% 13 / 18 Conditioncond 90.9% 10 / 11 MC/DCmcdc 85.7% 6 / 7 Subroutinesub 100% 10 / 10 Podpod 40.0% 2 / 5 totaltotal 90.2% 102 / 113 CC 14 SCAR 15.8
CC
14
Cov
92%
read
8.1
init
6.1
restore
2.0
CRAP 4.9
« OpenPGP/Compressed.pm ↑ Summary OpenPGP/Util.pm »
1 package Crypt::OpenPGP::Message;
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 our $VERSION = '1.21'; # VERSION
6  
7 11 ▶use Crypt::OpenPGP::Buffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Crypt::OpenPGP::PacketFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use parent qw( Crypt::OpenPGP::ErrorHandler );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12 11 my $class = shift;
13 11 my $msg = bless { }, $class;
14 11 $msg->init(@_);
15 }
16  
17 11 ▶sub init {
Subroutine init: called CC=6 SCAR=18.0
Pod undocumented
18 11 my $msg = shift;
19 11 my %param = @_;
20 11 $msg->{is_packet_stream} = delete $param{IsPacketStream};
21 11 $msg->{pieces} = [];
22 11 ▶ $msg->{_data} = $param{Data} || '';
Condition100%2/2
$param{'Data'} || ''
l!l
101
MC/DC100%1/1
$param{'Data'} || ''
$param{'Data'}
Truth table100%2/2
A
A= $param{'Data'}
Aresult
11
00
23 11 ▶ if (!$msg->{_data} && (my $file = $param{Filename})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $msg->{"_data"} and my $file = $param{"Filename"}) 1 10 11
Condition66%2/3
not $msg->{"_data"} and my $file = $param{"Filename"}
!ll&&!rl&&r
1001
MC/DC50%1/2
not $msg->{"_data"} and my $file = $param{"Filename"}
not $msg->{"_data"} my $file = $param{"Filename"}
Truth table66%2/3
not(A) and B
A= not $msg->{"_data"}B= my $file = $param{"Filename"}
ABresult
0X0
100
111
24 1 ▶ open ( my $fh, "<", $file ) or
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or return ref($msg)->error("Can't open message ${file}: $!") 1 0 1
25 return (ref $msg)->error("Can't open message $file: $!");
26 1 binmode $fh;
27 1 { local $/; $msg->{_data} = <$fh> }
28 1 close $fh;
29 }
30 11 ▶ $msg->read or return;
Branch: 1 branch
BranchTrueFalseTotal
$msg->read or return 9 0 9
31 9 $msg;
32 }
33  
34 11 ▶sub read {
Subroutine read: called CC=8 SCAR=20.9
Pod undocumented
35 11 my $msg = shift;
36 my $data = $msg->{_data} or
37 11 ▶ return $msg->error("Message contains no data");
Branch: 1 branch
BranchTrueFalseTotal
my $data = $msg->{"_data"} or return $msg->error("Message contains no data") 11 0 11
38 11 my $pt;
39 11 ▶ if (!$msg->{is_packet_stream} &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $msg->{"is_packet_stream"} and $data =~ /-----BEGIN PGP SIGNED MESSAGE/) 1 10 11
Condition100%3/3
not $msg->{"is_packet_stream"} and $data =~ /-----BEGIN PGP SIGNED MESSAGE/
!ll&&!rl&&r
281
MC/DC100%2/2
not $msg->{"is_packet_stream"} and $data =~ /-----BEGIN PGP SIGNED MESSAGE/
not $msg->{"is_packet_stream"} $data =~ /-----BEGIN PGP SIGNED MESSAGE/
Truth table100%3/3
not(A) and B
A= not $msg->{"is_packet_stream"}B= $data =~ /-----BEGIN PGP SIGNED MESSAGE/
ABresult
0X0
100
111
40 $data =~ /-----BEGIN PGP SIGNED MESSAGE/) {
41 1 require Crypt::OpenPGP::Armour;
42 1 require Crypt::OpenPGP::Util;
43 1 require Crypt::OpenPGP::Plaintext;
44 1 my($head, $text, $sig) = $data =~
45 m!-----BEGIN PGP SIGNED MESSAGE-----(.*?\r?\n\r?\n)?(.+?)(-----BEGIN PGP SIGNATURE.*?END PGP SIGNATURE-----)!s;
46 ## In clear-signed messages, the line ending before the signature
47 ## is not considered part of the signed text.
48 1 $text =~ s!\r?\n$!!;
49 1 $pt = Crypt::OpenPGP::Plaintext->new(
50 Data => Crypt::OpenPGP::Util::dash_unescape($text),
51 Mode => 't',
52 );
53 1 $data = $sig;
54 }
55  
56 11 ▶ if (!$msg->{is_packet_stream} && $data =~ /^-----BEGIN PGP/m) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $msg->{"is_packet_stream"} and $data =~ /^-----BEGIN PGP/m) 4 7 11
Condition100%3/3
not $msg->{"is_packet_stream"} and $data =~ /^-----BEGIN PGP/m
!ll&&!rl&&r
254
MC/DC100%2/2
not $msg->{"is_packet_stream"} and $data =~ /^-----BEGIN PGP/m
not $msg->{"is_packet_stream"} $data =~ /^-----BEGIN PGP/m
Truth table100%3/3
not(A) and B
A= not $msg->{"is_packet_stream"}B= $data =~ /^-----BEGIN PGP/m
ABresult
0X0
100
111
57 4 require Crypt::OpenPGP::Armour;
58 4 ▶ my $rec = Crypt::OpenPGP::Armour->unarmour($data) or
Branch: 1 branch
BranchTrueFalseTotal
my $rec = "Crypt::OpenPGP::Armour"->unarmour($data) or return $msg->error('Unarmour failed: ' . "Crypt::OpenPGP::Armour"->errstr) 4 0 4
59 return $msg->error("Unarmour failed: " .
60 Crypt::OpenPGP::Armour->errstr);
61 4 $data = $rec->{Data};
62 }
63 11 my $buf = Crypt::OpenPGP::Buffer->new;
64 11 $buf->append($data);
65 11 $msg->restore($buf);
66 0 ▶ push @{ $msg->{pieces} }, $pt if $pt;
Branch: 1 branch
BranchTrueFalseTotal
if $pt 0 9 9
67 9 1;
68 }
69  
70 11 ▶sub restore {
Subroutine restore: called CC=2 SCAR=6.9
Pod undocumented
71 11 my $msg = shift;
72 11 my($buf) = @_;
73 11 ▶ while (my $packet = Crypt::OpenPGP::PacketFactory->parse($buf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $packet = "Crypt::OpenPGP::PacketFactory"->parse($buf)) 17 9 26
74 17 push @{ $msg->{pieces} }, $packet;
75 }
76 }
77  
78 9 ▶sub pieces { @{ $_[0]->{pieces} } }
Subroutine pieces: called CC=1 SCAR=0.0
Pod documented
79  
80 11 1;
81 __END__
« OpenPGP/Compressed.pm ↑ Summary OpenPGP/Util.pm »