From: Nicholas Clark Date: Sat, 29 Nov 2003 17:04:39 +0000 (+0000) Subject: Update to Digest::MD5 2.31 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=49953a3f383b8241104c85e979c4a29a2f362e74;p=p5sagit%2Fp5-mst-13.2.git Update to Digest::MD5 2.31 p4raw-id: //depot/perl@21808 --- diff --git a/MANIFEST b/MANIFEST index 368cdbd..a4682af 100644 --- a/MANIFEST +++ b/MANIFEST @@ -188,6 +188,7 @@ ext/Digest/MD5/MD5.xs Digest::MD5 extension ext/Digest/MD5/README Digest::MD5 extension Readme ext/Digest/MD5/t/align.t See if Digest::MD5 extension works ext/Digest/MD5/t/badfile.t See if Digest::MD5 extension works +ext/Digest/MD5/t/bits.t See if Digest::MD5 extension works ext/Digest/MD5/t/clone.t See if Digest::MD5 extension works ext/Digest/MD5/t/files.t See if Digest::MD5 extension works ext/Digest/MD5/t/md5-aaa.t See if Digest::MD5 extension works diff --git a/ext/Digest/MD5/Changes b/ext/Digest/MD5/Changes index a6e3dd8..97a2c50 100644 --- a/ext/Digest/MD5/Changes +++ b/ext/Digest/MD5/Changes @@ -1,3 +1,11 @@ +2003-11-28 Gisle Aas + + Release 2.31 + + Inherit add_bits() from Digest::base if available. + + + 2003-10-09 Gisle Aas Release 2.30 diff --git a/ext/Digest/MD5/MD5.pm b/ext/Digest/MD5/MD5.pm index 29a2ab5..13342b5 100644 --- a/ext/Digest/MD5/MD5.pm +++ b/ext/Digest/MD5/MD5.pm @@ -3,7 +3,7 @@ package Digest::MD5; use strict; use vars qw($VERSION @ISA @EXPORT_OK); -$VERSION = '2.30'; # $Date: 2003/10/09 09:26:59 $ +$VERSION = '2.31'; # $Date: 2003/11/28 13:06:19 $ require Exporter; *import = \&Exporter::import; @@ -13,6 +13,16 @@ require DynaLoader; @ISA=qw(DynaLoader); eval { + require Digest::base; + push(@ISA, 'Digest::base'); +}; +if ($@) { + my $err = $@; + *add_bits = sub { die $err }; +} + + +eval { Digest::MD5->bootstrap($VERSION); }; if ($@) { @@ -173,6 +183,16 @@ or reset the $md5 object if this occurs. In most cases you want to make sure that the $io_handle is in C before you pass it as argument to the addfile() method. +=item $md5->add_bits($data, $nbits) + +=item $md5->add_bits($bitstring) + +Since the MD5 algorithm is byte oriented you might only add bits as +multiples of 8, so you probably want to just use add() instead. The +add_bits() method is provided for compatibility with other digest +implementations. See L for description arguments to +add_bits(). + =item $md5->digest Return the binary digest for the message. The returned string will be diff --git a/ext/Digest/MD5/Makefile.PL b/ext/Digest/MD5/Makefile.PL index b2c974e..e0db567 100644 --- a/ext/Digest/MD5/Makefile.PL +++ b/ext/Digest/MD5/Makefile.PL @@ -1,4 +1,6 @@ -require 5.004; +#!perl -w + +BEGIN { require 5.004 } use strict; use Config qw(%Config); use ExtUtils::MakeMaker; @@ -20,7 +22,9 @@ push(@extra, 'INSTALLDIRS' => 'perl') if $] >= 5.008; WriteMakefile( 'NAME' => 'Digest::MD5', 'VERSION_FROM' => 'MD5.pm', - MAN3PODS => {}, # Pods will be built by installman. + 'PREREQ_PM' => { 'File::Spec' => 0, + 'Digest::base' => '1.00', + }, @extra, 'dist' => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, ); @@ -29,7 +33,101 @@ WriteMakefile( sub free_u32_alignment { - return 0 if $Config{d_u32align}; - return 1 if $Config{'byteorder'} eq '1234' || $Config{'byteorder'} eq '4321'; + $|=1; + print "Testing alignment requirements for U32... "; + return 1 if $^O eq 'VMS'; + return 1 if $^O eq 'MSWin32'; + + open(ALIGN_TEST, ">u32align.c") or die "$!"; + print ALIGN_TEST <<'EOT'; close(ALIGN_TEST); +/*--------------------------------------------------------------*/ +/* This program allocates a buffer of U8 (char) and then tries */ +/* to access it through a U32 pointer at every offset. The */ +/* program is expected to die with a bus error/seg fault for */ +/* machines that do not support unaligned integer read/write */ +/*--------------------------------------------------------------*/ + +#include +#include "EXTERN.h" +#include "perl.h" + +#ifdef printf + #undef printf +#endif + +int main(int argc, char** argv, char** env) +{ +#if BYTEORDER == 0x1234 || BYTEORDER == 0x4321 + U8 buf[] = "\0\0\0\1\0\0\0\0"; + U32 *up; + int i; + + if (sizeof(U32) != 4) { + printf("sizeof(U32) is not 4, but %d\n", sizeof(U32)); + exit(1); + } + + fflush(stdout); + + for (i = 0; i < 4; i++) { + up = (U32*)(buf + i); + if (! ((*up == 1 << (8*i)) || /* big-endian */ + (*up == 1 << (8*(3-i))) /* little-endian */ + ) + ) + { + printf("read failed (%x)\n", *up); + exit(2); + } + } + + /* write test */ + for (i = 0; i < 4; i++) { + up = (U32*)(buf + i); + *up = 0xBeef; + if (*up != 0xBeef) { + printf("write failed (%x)\n", *up); + exit(3); + } + } + + printf("no restrictions\n"); + exit(0); +#else + printf("unusual byteorder, playing safe\n"); + exit(1); +#endif + return 0; +} +/*--------------------------------------------------------------*/ +EOT + + my $cc_cmd = "$Config{cc} $Config{ccflags} -I$Config{archlibexp}/CORE"; + my $exe = "u32align$Config{exe_ext}"; + $cc_cmd .= " -o $exe"; + my $rc; + $rc = system("$cc_cmd $Config{ldflags} u32align.c $Config{libs}"); + if ($rc) { + print "Can't compile test program. Will ensure alignment to play safe.\n\n"; + unlink("u32align.c", $exe, "u32align$Config{obj_ext}"); + return 0; + } + + $rc = system("./$exe"); + unlink("u32align.c", $exe, "u32align$Config{obj_ext}"); + + return 1 unless $rc; + + if ($rc > 0x80) { + $rc >>= 8; + print "Test program exit status was $rc\n"; + } else { + if ($rc & 0x80) { + $rc &= ~0x80; + print "Core dump deleted\n"; + unlink("core"); + } + print "signal $rc\n"; + } return 0; } diff --git a/ext/Digest/MD5/t/badfile.t b/ext/Digest/MD5/t/badfile.t index 4b3a331..28e0b90 100644 --- a/ext/Digest/MD5/t/badfile.t +++ b/ext/Digest/MD5/t/badfile.t @@ -1,10 +1,6 @@ -# Digest::MD5 2.07 and older used to trigger a core dump when -# passed an illegal file handle that failed to open. - -print "1..3\n"; +print "1..2\n"; use Digest::MD5 (); -use Config; $md5 = Digest::MD5->new; @@ -21,20 +17,3 @@ eval { }; print "not " unless $@ =~ /^No filehandle passed at/; print "ok 2\n"; - -open(BAR, ">no-existing-file.$$") || die; -eval { - $md5->addfile(*BAR); -}; -# Some stdio implementations don't find reading from -# write-only filehandle to be a problem. Therefore we -# cannot expect this to fail reliably with stdio. -my $stdio = !exists $Config{useperlio} || - !defined $Config{useperlio} || - (exists $ENV{PERLIO} && $ENV{PERLIO} eq 'stdio') || - defined $Config{usefaststdio}; -print "not " unless $@ =~ /^Reading from filehandle failed at/ || $stdio; -print "ok 3\n"; - -close(BAR); -unlink("no-existing-file.$$"); diff --git a/ext/Digest/MD5/t/bits.t b/ext/Digest/MD5/t/bits.t new file mode 100644 index 0000000..db3b693 --- /dev/null +++ b/ext/Digest/MD5/t/bits.t @@ -0,0 +1,26 @@ +#!perl -w + +use Test qw(plan ok); +plan tests => 2; + +use Digest::MD5; + +my $md5 = Digest::MD5->new; + +if ($Digest::base::VERSION) { + $md5->add_bits("01111111"); + ok($md5->hexdigest, "83acb6e67e50e31db6ed341dd2de1595"); + eval { + $md5->add_bits("0111"); + }; + ok($@ =~ /must be multiple of 8/); +} +else { + print "# No Digest::base\n"; + eval { + $md5->add_bits("foo"); + }; + ok($@ =~ /^Can\'t locate Digest\/base\.pm in \@INC/); + ok(1); # dummy +} + diff --git a/ext/Digest/MD5/t/files.t b/ext/Digest/MD5/t/files.t index bc4bddc..fd965ca 100644 --- a/ext/Digest/MD5/t/files.t +++ b/ext/Digest/MD5/t/files.t @@ -20,26 +20,26 @@ use Digest::MD5 qw(md5 md5_hex md5_base64); my $EXPECT; if (ord "A" == 193) { # EBCDIC $EXPECT = <