lestrrat has asked for the wisdom of the Perl Monks concerning the following question:
I thought I knew how to use Digest::(MD5|SHA1), but apparently not. I've found out that when I have a function like this:
sub generate_signature { my $fh = shift; my $digest = Digest::SHA1->new(); $digest->addfile($fh); return $digest->sha1_hex(); }
I get different results for the first time I call the function and the subsequent calls in the same process. The sequence is always the same, though... and it looks something like this:
Signature for test.pl is bd7ce45573c74ca2373ddaf2f87fd7047bd1c6c7 Signature for test.pl is acdae4cd87ebecf0d2a4c96bec4282bb98adf831
But the two digests that I get are always the same, it's just that successive calls within the same process seem to stack the previous data passed by add() or addfile()
This leads me to believe that some how Digest::SHA1 is not resetting its state when new() is called.... I tried calling reset(), but that didn't work either.
Am I missing something? Is there a workaround?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to force Digest::SHA1/MD5 to reset?
by antirice (Priest) on Oct 21, 2003 at 21:44 UTC | |
by lestrrat (Deacon) on Oct 21, 2003 at 22:18 UTC | |
|
Re: How to force Digest::SHA1/MD5 to reset?
by sauoq (Abbot) on Oct 21, 2003 at 21:43 UTC |