| 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'} || ''
MC/DC100%1/1
$param{'Data'} || ''
$param{'Data'}
Truth table100%2/2
A
A= $param{'Data'}
| |||||||||||||||||||||||||||||
| 23 | 11 | ▶ | if (!$msg->{_data} && (my $file = $param{Filename})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $msg->{"_data"} and my $file = $param{"Filename"}
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"}
| |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | open ( my $fh, "<", $file ) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 38 | 11 | my $pt; | |||||||||||||||||||||||||||
| 39 | 11 | ▶ | if (!$msg->{is_packet_stream} && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $msg->{"is_packet_stream"} and $data =~ /-----BEGIN PGP SIGNED MESSAGE/
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/
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
not $msg->{"is_packet_stream"} and $data =~ /^-----BEGIN PGP/m
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
| |||||||||||||||||||||||||||||
| 57 | 4 | require Crypt::OpenPGP::Armour; | |||||||||||||||||||||||||||
| 58 | 4 | ▶ | my $rec = Crypt::OpenPGP::Armour->unarmour($data) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||