Skip Menu |

This queue is for tickets about the Digest-MD5 CPAN distribution.

Report information
The Basics
Id: 749
Status: resolved
Worked: 5 min
Priority: 0/
Queue: Digest-MD5

People
Owner: Nobody in particular
Requestors: B.Schofield [...] mailbox.gu.edu.au
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.20
Fixed in: (no value)



Subject: Difference between funcitonal and OO invocation methods
The two scripts "md5_test_oo.pl" and "md5_test_func.pl" output the following results: %perl md5_test_func.pl test md5($data) = ?kÍF!ÓsÊÞNƒ&'´ö md5_hex($data) = 098f6bcd4621d373cade4e832627b4f6 md5_base64($data) = CY9rzUYh03PK3k6DJie09g %perl md5_test_oo.pl test $ctx->digest = ?kÍF!ÓsÊÞNƒ&'´ö $ctx->hexdigest = d41d8cd98f00b204e9800998ecf8427e $ctx->b64digest = 1B2M2Y8AsgTpgAmY7PhCfg while the digest data is the same for both cases the hexdigest and base64 digest data is different. Can you please explain why. ----8<---- %more md5_test_func.pl #!/usr/bin/perl use Digest::MD5 qw(md5 md5_hex md5_base64); my $data = "test"; print "$data\n"; $digest = md5($data); print "md5(\$data) =\t$digest\n"; $digest = md5_hex($data); print "md5_hex(\$data) =\t$digest\n"; $digest = md5_base64($data); print "md5_base64(\$data) =\t$digest\n"; ----8<---- %more md5_test_oo.pl #!/usr/bin/perl use Digest::MD5; my $data = "test"; print "$data\n"; $ctx = Digest::MD5->new; $ctx->add($data); $digest = $ctx->digest; print "\$ctx->digest =\t$digest\n"; $digest = $ctx->hexdigest; print "\$ctx->hexdigest =\t$digest\n"; $digest = $ctx->b64digest; print "\$ctx->b64digest =\t$digest\n"; %uname -a FreeBSD 4.5-STABLE FreeBSD 4.5-STABLE #0: Fri Mar 15 16:48:57 EST 2002 root@pc056945.ins.gu.edu.au:/u1/usr/obj/u1/usr/src/sys/GENERIC i386 -Brook
The description of the 'digest' method says: Note that the "digest" operation is effectively a destructive, read-once operation. Once it has been performed, the "Digest::MD5" object is automatically "reset" and can be used to calculate another digest value. This explains the behaviour you see in your example. The calls to $ctx->hexdigest and $ctx->b64digest will return the digesst for the empty string.