| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | package Slackware::Slackget::MD5; | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 5 |  |  | 5 |  | 41 | use warnings; | 
|  | 5 |  |  |  |  | 12 |  | 
|  | 5 |  |  |  |  | 243 |  | 
| 5 | 5 |  |  | 5 |  | 53 | use strict; | 
|  | 5 |  |  |  |  | 11 |  | 
|  | 5 |  |  |  |  | 2599 |  | 
| 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 |  |  |  |  |  |  | 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 |  |  |  |  |  |  | { | 
| 41 | 0 |  |  | 0 | 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 |  |  |  |  |  |  | { | 
| 69 | 0 |  |  | 0 | 1 |  | my ($self,$file) = @_; | 
| 70 | 0 | 0 | 0 |  |  |  | return undef if(ref($self) eq '' || !$self->can("get_value")) ; | 
| 71 | 0 |  |  |  |  |  | my $out = `2>&1 LANG=en_US md5sum $file`; | 
| 72 | 0 |  |  |  |  |  | chomp $out; | 
| 73 | 0 | 0 |  |  |  |  | if($out=~ /^([^\s]+)\s+.*/) | 
| 74 |  |  |  |  |  |  | { | 
| 75 | 0 |  |  |  |  |  | my $tmp_md5 = $1; | 
| 76 | 0 |  |  |  |  |  | print "\$tmp_md5 : $tmp_md5\n"; | 
| 77 | 0 | 0 |  |  |  |  | if($file =~ /\.tgz$/) | 
|  |  | 0 |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | { | 
| 79 | 0 |  |  |  |  |  | $self->set_value('computed-checksum',$tmp_md5); | 
| 80 | 0 | 0 |  |  |  |  | if($self->get_value('checksum') eq $tmp_md5) | 
| 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 | 0 |  |  |  |  | if($self->get_value('signature-checksum') eq $tmp_md5) | 
| 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<<  >> | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =head1 BUGS | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | Please report any bugs or feature requests to | 
| 117 |  |  |  |  |  |  | C, or through the web interface at | 
| 118 |  |  |  |  |  |  | L. | 
| 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 | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =item * slack-get specific website | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | L | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =item * RT: CPAN's request tracker | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | L | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | L | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | L | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =item * Search CPAN | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | L | 
| 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 |  |  |  |  |  |  | 1; # Fin de Slackware::Slackget::MD5 | 
| 175 |  |  |  |  |  |  |  |