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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.