| 1 | |||||||||||||||||||||||||||||
| 2 | package Slackware::Slackget::MD5; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 NOM | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | Slackware::Slackget::MD5 - A simple class to verify files checksums | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 VERSION | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Version 0.2 | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 7 | our $VERSION = '0.2'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | A simple class to verify files checksums with md5sum. | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | use Slackware::Slackget::MD5; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | my $slackget10_gpg_object = Slackware::Slackget::MD5->new(); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | IMPORTANT NOTE : This class is not design to be use by herself (the constructor for example is totaly useless). the Slackware::Slackget::Package class inheritate of this class and this is the way is design Slackware::Slackget::MD5 : to be only an abstraction of the MD5 verification operations. | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | You may prefer to inheritate from this class, but take attention to the fact that I design it to be inheritate by the Slackware::Slackget::Package class ! | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | new() : The constructor doesn't take any arguments but be sure the md5sum binary is in the PATH ! | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub new | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 0 | my ($class,%args) = @_ ; | |||||||||||||||||||||||||||
| 42 | 0 | my $self={}; | |||||||||||||||||||||||||||
| 43 | 0 | bless($self,$class); | |||||||||||||||||||||||||||
| 44 | 0 | return $self; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =head1 METHODS | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head2 verify_md5 | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | This method call the getValue() accessor (from the Slackware::Slackget::Package class) on the 'checksum' or 'signature-checksum' field, and check if it match with the MD5 of the file passed in argument. | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | If the argument ends with ".tgz" this method use the 'checksum' field and if it ends with ".asc" it use the 'signature-checksum' field. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | $package->verify_md5("/home/packages/update/package-cache/apache-1.3.33-i486-1.tgz") && $sgo->installpkg($packagelist->get_indexed("apache-1.3.33-i486-1")) ; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Returned values : | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | undef : if a problem occur (ex: the current instance do not inheritate from Slackware::Slackget::Package, the file is not a package nor a signature, etc.) | ||||||||||||||||||||||||||||
| 60 | 1 : if the MD5 is ok | ||||||||||||||||||||||||||||
| 61 | 0 : if not. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | This method also set a 'computed-checksum' and a 'computed-signature-checksum' in the current Slackware::Slackget::Package object. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub verify_md5 | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
verify_md5: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 0 | my ($self,$file) = @_; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | return undef if(ref($self) eq '' || !$self->can("get_value")) ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $self eq "" or not $self->can("get_value")
MC/DC0%0/2
ref $self eq "" or not $self->can("get_value")
ref $self eq ""
not $self->can("get_value")
Truth table0%0/3
A or not(B)
A= ref $self eq ""B= not $self->can("get_value")
| |||||||||||||||||||||||||||||
| 71 | 0 | my $out = `2>&1 LANG=en_US md5sum $file`; | |||||||||||||||||||||||||||
| 72 | 0 | chomp $out; | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | if($out=~ /^([^\s]+)\s+.*/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | 0 | my $tmp_md5 = $1; | |||||||||||||||||||||||||||
| 76 | 0 | print "\$tmp_md5 : $tmp_md5\n"; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | if($file =~ /\.tgz$/) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||
| 79 | 0 | $self->set_value('computed-checksum',$tmp_md5); | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | if($self->get_value('checksum') eq $tmp_md5) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | 0 | return 1; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | else | ||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 0 | return 0; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | elsif($file =~ /\.asc$/) | ||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 0 | $self->set_value('computed-signature-checksum',$tmp_md5); | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | if($self->get_value('signature-checksum') eq $tmp_md5) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||
| 94 | 0 | return 1; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | else | ||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||
| 98 | 0 | return 0; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | else | ||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||
| 103 | 0 | return undef; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | return undef; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | DUPUIS Arnaud, C<< <a.dupuis@infinityperl.org> >> | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head1 BUGS | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||
| 117 | C<bug-Slackware-Slackget@rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||
| 118 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Slackware-Slackget>. | ||||||||||||||||||||||||||||
| 119 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 120 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | perldoc Slackware::Slackget | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | You can also look for information at: | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =over 4 | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =item * Infinity Perl website | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | L<http://www.infinityperl.org/category/slack-get> | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =item * slack-get specific website | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | L<http://slackget.infinityperl.org> | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Slackware-Slackget> | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | L<http://annocpan.org/dist/Slackware-Slackget> | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | L<http://cpanratings.perl.org/d/Slackware-Slackget> | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | L<http://search.cpan.org/dist/Slackware-Slackget> | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =back | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Copyright 2005 DUPUIS Arnaud, All Rights Reserved. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 170 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 7 | 1; # Fin de Slackware::Slackget::MD5 | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||