Hi Perl Monks!
I've written a small perl script (which will run on Windows most of the time) to calculate the latest version in a Nexus repository (given some information about group id, artefact name and type) and download the artefact. I decided to put in a little belt-and-braces and check the SHA1 value on the remote site against the calculated SHA1 of the downloaded file.
Here's the rub: my perl-calculated value (using Digest::SHA1) is different from both the SHA1 on the remote site, and that calculated on the downloaded file using FCIV.
My subs for calculating and downloading SHA1 values:
sub computeSHA1 () { # Passed a file path, opens the file and calculates the SHA1 value my $srcfile = shift; print "DEBUG: computeSHA1: arrived\n" if ($debug); my $sha1post = Digest::SHA1->new; open my $filehandle, $srcfile or &usage("computeSHA: Failed to ope +n " . $srcfile . ": " . $!, 2); $sha1post->addfile($filehandle); print "DEBUG: downloadSHA1: Calculating SHA1 for $srcfile\n" if ($ +debug); close $filehandle; return $sha1post->hexdigest; } sub downloadSHA1 () { # Passed a URL for a file, looks for the SHA1 file and returns the + value my $url = shift; print "DEBUG: downloadSHA1: arrived\n" if ($debug); my $SHAurl = $url . ".sha1"; my $browser = LWP::UserAgent->new; # Get the SHA1 value from $SHAurl my $SHAcall = $browser->get($SHAurl); print "DEBUG: downloadSHA1: Getting SHA1 from $SHAurl\n" if ($debu +g); &usage("downloadSHA1: Could not fetch SHA1 at " . $SHAurl, 5) unle +ss $SHAcall->is_success; return $SHAcall->content; }
Here's the command-line testing (the subroutine above returns the same value as the perl call below - the Nexus server stores the same value as the FCIV call below):
C:\TaskServer>c:\software\fciv\fciv -sha1 gbmiportal-4.0.0.791577-SNAP +SHOT.ear // // File Checksum Integrity Verifier version 2.05. // 0ad3530689d273b472d4b20835476b756c6361af gbmiportal-4.0.0.791577-snaps +hot.ear C:\TaskServer>perl -MDigest::SHA1=sha1_hex -le "print sha1_hex <>" gbm +iportal-4.0.0.791577-SNAPSHOT.ear 8d829b7cdf254f01b1e217f3dfd28c2539891f8f
Thanks in advance for your assistance! I'm probably doing something really dumb... Adam...
In reply to SHA1 calculations using Digest::SHA1 do not agree by AdamtheKiwi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |