« 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"} ||= {}
MC/DC0%0/1
$meta->prop->{"digest"} ||= {}
$meta->prop->{"digest"}
Truth table50%1/2
A
A= $meta->prop->{"digest"}
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | 16 | ▶ | if(ref($self->sig) eq 'HASH') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 64 | } | ||||||||||||||
| 65 | 15 | $res; | |||||||||||||
| 66 | }, | ||||||||||||||
| 67 | 16 | ▶ | ) if $self->check_fetch; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 76 | 14 | $build->check_digest($path); | |||||||||||||
| 77 | }, | ||||||||||||||
| 78 | 16 | ▶ | ) if $self->check_download; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 4 | 1; | |||||||||||||
| 82 | |||||||||||||||
| 83 | __END__ | ||||||||||||||