blib/lib/Alien/Build/Plugin/Digest/Negotiate.pm

filter: Statementstmt 100% 44 / 44 Branchbran 66.6% 12 / 18 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 89.0% 65 / 73 CC 12 SCAR 17.2
CC
12
Cov
89%
init
9.3
__ANON__
3.0
__ANON__
2.0
CRAP 5.6
« corpus/lib/Alien/Build/Plugin/Fetch/Corpus.pm ↑ Summary blib/lib/Alien/Build/Plugin/Decode/Mojo.pm »
1 package Alien::Build::Plugin::Digest::Negotiate;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Alien::Build::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ABSTRACT: Plugin negotiator for cryptographic signatures
8 4 our $VERSION = '2.88'; # VERSION
9  
10  
11 3 ▶has '+sig' => sub { {} };
Subroutine __ANON__: called CC=1 SCAR=0.0
12  
13 4 has check_fetch => 1;
14 4 has check_download => 1;
15 4 has allow_listing => 1;
16  
17 sub init
18 16 ▶{
Subroutine init: called CC=9 SCAR=22.2
Pod documented
19 16 my($self, $meta) = @_;
20 16 $meta->add_requires('configure' => 'Alien::Build::Plugin::Digest::Negotiate' => "0" );
21  
22 16 $meta->prop->{check_digest} = 1;
23  
24 16 ▶ my $sigs = $meta->prop->{digest} ||= {};
Condition50%1/2
$meta->prop->{"digest"} ||= {}
l!l
016
MC/DC0%0/1
$meta->prop->{"digest"} ||= {}
$meta->prop->{"digest"}
Truth table50%1/2
A
A= $meta->prop->{"digest"}
Aresult
11
00
25  
26 16 ▶ if(ref($self->sig) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->sig eq 'HASH') { } 4 12 16
elsif (ref $self->sig eq 'ARRAY') { } 12 0 12
27  
28 4 foreach my $filename (keys %{ $self->sig })
29 {
30 3 my $signature = $self->sig->{$filename};
31 3 my($algo) = @$signature;
32 3 ▶ die "Unknown digest algorithm $algo" unless $algo =~ /^SHA(1|224|256|384|512|512224|512256)$/; # reportedly what is supported by Digest::SHA
Branch: 1 branch
BranchTrueFalseTotal
unless $algo =~ /^SHA(1|224|256|384|512|512224|512256)$/ 0 3 3
33 3 $sigs->{$filename} = $signature;
34 }
35  
36 } elsif(ref($self->sig) eq 'ARRAY') {
37  
38 12 my $signature = $self->sig;
39 12 my($algo) = @$signature;
40 12 ▶ die "Unknown digest algorithm $algo" unless $algo =~ /^SHA(1|224|256|384|512|512224|512256)$/; # reportedly what is supported by Digest::SHA
Branch: 1 branch
BranchTrueFalseTotal
unless $algo =~ /^SHA(1|224|256|384|512|512224|512256)$/ 0 12 12
41 12 $sigs->{'*'} = $signature;
42 }
43  
44 # In the future if this negotiator supports algorithms other
45 # than SHA, we should probably ajust this to keep track of
46 # which ones we actually need when we are looping through them
47 # above. Also technically you could call this plugin without
48 # any sigs, and we shouldn't in theory need to apply Digest::SHA,
49 # but stuff won't work that way so that is a corner case we
50 # are not going to worry about.
51 16 $meta->apply_plugin('Digest::SHA');
52  
53 $meta->around_hook(
54 19 ▶ fetch => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
55 19 my($orig, $build, @rest) = @_;
56 19 my $res = $orig->($build, @rest);
57 19 ▶ if($res->{type} eq 'file')
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{'type'} eq 'file') { } 16 3 19
58 {
59 16 $build->check_digest($res);
60 }
61 else
62 {
63 3 ▶ die "listing fetch not allowed" unless $self->allow_listing;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->allow_listing 1 2 3
64 }
65 15 $res;
66 },
67 16 ▶ ) if $self->check_fetch;
Branch: 1 branch
BranchTrueFalseTotal
if $self->check_fetch 16 0 16
68  
69 # Note that check_download hook is currently undocumented and
70 # may change in the future.
71 $meta->register_hook(
72 14 ▶ check_download => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
73 14 my($build) = @_;
74 14 my $path = $build->install_prop->{download};
75 14 ▶ die "Checking cryptographic signatures on download only works for single archive" unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 14 14
76 14 $build->check_digest($path);
77 },
78 16 ▶ ) if $self->check_download;
Branch: 1 branch
BranchTrueFalseTotal
if $self->check_download 16 0 16
79 }
80  
81 4 1;
82  
83 __END__
« corpus/lib/Alien/Build/Plugin/Fetch/Corpus.pm ↑ Summary blib/lib/Alien/Build/Plugin/Decode/Mojo.pm »