Thank you very much! That was very helpful in debugging a problem with 
SpamAssassin's sa-update.

Best regards,
Martin

-----Ursprüngliche Nachricht-----
Von: sisyph...@optusnet.com.au [mailto:sisyph...@optusnet.com.au]
Gesendet: Montag, 15. Mai 2017 16:31
An: Martin Puppe <pu...@jam-software.com>; win32-vanilla@perl.org
Betreff: Re: Wrong SHA1 is calculated


From: Martin Puppe
Sent: Monday, May 15, 2017 8:39 PM
To: win32-vanilla@perl.org
Subject: Wrong SHA1 is calculated

> Hello,
>
> I am debugging a problem with SHA1 checksums. I have found the
> following handy one-liner on Stack Overflow [^1], which serves well as
> a minimal
> example:
>
> perl -MDigest::SHA1=sha1_hex -le "print sha1_hex <>" secure.txt
>
> The problem is, that the result is simply not correct.Martin Puppe

The same web page presents a program which should provide the same "not 
correct" result.
I've inserted "binmode $fh;" into it - which then allows it to return the 
"correct" value:

#############################
use warnings;
use strict;

use Digest::SHA1;

die "Usage: $0 file ..\n" unless @ARGV;

foreach my $file (@ARGV) {
  my $fh;
  unless (open $fh, $file) {
    warn "$0: open $file: $!";
    next;
  }

  binmode $fh; # inserted by sisyphus
  my $sha1 = Digest::SHA1->new;
  $sha1->addfile($fh);
  print $sha1->hexdigest, "  $file\n";

  close $fh;
}
###############################

If 'secure.txt' is a plain text file with Unix line endings, then that
binmode() should not be necessary - but if the text file has Windows line 
endings then binmode() will prevent their translation to Unix endings (and the 
program will return the result that you expect).

Unfortunately, I don't know how to get that binmode() into the one-liner's 
angle brackets :-(

Maybe someone else here can chime in.

Cheers,
Rob



________________________________



--------------------------------------------------------
JAM Software GmbH
Managing Director: Joachim Marder
Am Wissenschaftspark 26 * 54296 Trier * Germany
Phone: +49 (0)651-145 653 -0 * Fax: +49 (0)651-145 653 -29
Commercial register number HRB 4920 (AG Wittlich) http://www.jam-software.com

________________________________



----------------------------------------------------
JAM Software GmbH
Geschäftsführer: Joachim Marder
Am Wissenschaftspark 26 * 54296 Trier * Germany
Tel: 0651-145 653 -0 * Fax: 0651-145 653 -29
Handelsregister Nr. HRB 4920 (AG Wittlich) http://www.jam-software.de

Reply via email to