line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
1551
|
use v5.14.0; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package OS::Package::Artifact::Role::Validate; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Provides the validation methods for Artifact role. |
7
|
|
|
|
|
|
|
our $VERSION = '0.2.6'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use Digest::MD5; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
10
|
1
|
|
|
1
|
|
1618
|
use Digest::SHA; |
|
1
|
|
|
|
|
5809
|
|
|
1
|
|
|
|
|
100
|
|
11
|
1
|
|
|
1
|
|
84
|
use OS::Package::Log; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Path::Tiny; |
13
|
|
|
|
|
|
|
use Role::Tiny; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub validate { |
16
|
|
|
|
|
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
if ( defined $self->md5 ) { |
19
|
|
|
|
|
|
|
if ( !$self->validate_md5 ) { |
20
|
|
|
|
|
|
|
return 0; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if ( defined $self->sha1 ) { |
25
|
|
|
|
|
|
|
if ( !$self->validate_sha1 ) { |
26
|
|
|
|
|
|
|
return 0; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return 1; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub validate_md5 { |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $md5 = Digest::MD5->new(); |
37
|
|
|
|
|
|
|
my $fh = path( $self->savefile )->openr; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$md5->addfile($fh) |
40
|
|
|
|
|
|
|
or |
41
|
|
|
|
|
|
|
$LOGGER->logcroak( sprintf 'cannot open file %s', $self->savefile ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
if ( $md5->hexdigest eq $self->md5 ) { |
44
|
|
|
|
|
|
|
$LOGGER->info( sprintf 'md5 checksum ok: %s', $self->distfile ); |
45
|
|
|
|
|
|
|
return 1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$LOGGER->fatal( sprintf 'md5 checksum bad: %s', $self->distfile ); |
49
|
|
|
|
|
|
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub validate_sha1 { |
53
|
|
|
|
|
|
|
my $self = shift; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $sha = Digest::SHA->new; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$sha->addfile( $self->savefile ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if ( $sha->hexdigest eq $self->sha1 ) { |
60
|
|
|
|
|
|
|
$LOGGER->info( sprintf 'sha1 checksum ok: %s', $self->distfile ); |
61
|
|
|
|
|
|
|
return 1; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$LOGGER->fatal( sprintf 'sha1 checksum bad: %s', $self->distfile ); |
65
|
|
|
|
|
|
|
return 0; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |