diff options
author | Gisle Aas <gisle@aas.no> | 2002-12-29 23:38:16 -0800 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2003-01-16 19:56:07 +0000 |
commit | 9a03235d71a6ebc5a1eb9cdd3a23e531d8645e9c (patch) | |
tree | 8fa4a9a7d623c9a733c95e70980fb6d0d0cb4e10 /ext/Digest | |
parent | 581883cdf264875c9c1f1fd2c8d45ef942f553c1 (diff) | |
download | perl-9a03235d71a6ebc5a1eb9cdd3a23e531d8645e9c.tar.gz |
Update for ext/Digest/MD5/
Message-ID: <lrd6njzfdj.fsf@caliper.activestate.com>
p4raw-id: //depot/perl@18492
Diffstat (limited to 'ext/Digest')
-rw-r--r-- | ext/Digest/MD5/Changes | 14 | ||||
-rw-r--r-- | ext/Digest/MD5/MD5.pm | 25 | ||||
-rw-r--r-- | ext/Digest/MD5/Makefile.PL | 19 | ||||
-rw-r--r-- | ext/Digest/MD5/t/align.t | 6 | ||||
-rw-r--r-- | ext/Digest/MD5/t/files.t | 29 |
5 files changed, 66 insertions, 27 deletions
diff --git a/ext/Digest/MD5/Changes b/ext/Digest/MD5/Changes index a100886e79..2500b89d50 100644 --- a/ext/Digest/MD5/Changes +++ b/ext/Digest/MD5/Changes @@ -1,3 +1,17 @@ +2002-12-27 Gisle Aas <gisle@ActiveState.com> + + Release 2.21 + + Minor tweaks sync up with bleadperl: + - VMS optimizer tweaks to the Makefile.PL + - MacOS support + - Added alignment test + + Added example to the MD5 POD that shows how to calculate the + digest of Unicode strings. + + + 2002-05-05 Gisle Aas <gisle@ActiveState.com> Release 2.20 diff --git a/ext/Digest/MD5/MD5.pm b/ext/Digest/MD5/MD5.pm index 372e007cb7..08e616e67b 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.20'; # $Date: 2002/05/06 05:15:09 $ +$VERSION = '2.21'; # $Date: 2002/12/28 05:30:03 $ require Exporter; *import = \&Exporter::import; @@ -214,6 +214,29 @@ the file: print Digest::MD5->new->addfile(*FILE)->hexdigest, " $file\n"; +Perl 5.8 support Unicode characters in strings. Since the MD5 +algorithm is only defined for strings of bytes, it can not be used on +strings that contains chars with ordinal number above 255. The MD5 +functions and methods will croak if you try to feed them such input +data: + + use Digest::MD5 qw(md5_hex); + + my $str = "abc\x{300}"; + print md5_hex($str), "\n"; # croaks + # Wide character in subroutine entry + +What you can do is calculate the MD5 checksum of the UTF-8 +representation of such strings. This is achieved by filtering the +string through encode_utf8() function: + + use Digest::MD5 qw(md5_hex); + use Encode qw(encode_utf8); + + my $str = "abc\x{300}"; + print md5_hex(encode_utf8($str)), "\n"; + # 8c2d46911f3f5a326455f0ed7a8ed3b3 + =head1 SEE ALSO L<Digest>, diff --git a/ext/Digest/MD5/Makefile.PL b/ext/Digest/MD5/Makefile.PL index 3a6450ccaf..ceae9493f0 100644 --- a/ext/Digest/MD5/Makefile.PL +++ b/ext/Digest/MD5/Makefile.PL @@ -4,29 +4,32 @@ use Config qw(%Config); use ExtUtils::MakeMaker; my @extra; +@extra = (DEFINE => "-DU32_ALIGNMENT_REQUIRED") unless free_u32_alignment(); -unless ($Config{d_u32align}) { - @extra = (DEFINE => "-DU32_ALIGNMENT_REQUIRED") - if !($Config{'byteorder'} eq '1234' || - $Config{'byteorder'} eq '4321'); -} -my @optimize = (); if ($^O eq 'VMS') { if (defined($Config{ccname})) { if (grep(/VMS_VAX/, @INC) && ($Config{ccname} eq 'DEC')) { # VAX compiler optimizer even as late as v6.4 gets stuck - @optimize = ("OPTIMIZE","/Optimize=(NODISJOINT)"); + push(@extra, OPTIMIZE => "/Optimize=(NODISJOINT)"); } } } + WriteMakefile( 'NAME' => 'Digest::MD5', 'VERSION_FROM' => 'MD5.pm', MAN3PODS => {}, # Pods will be built by installman. @extra, 'dist' => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, - @optimize ); exit; + + +sub free_u32_alignment +{ + return 0 if $Config{d_u32align}; + return 1 if $Config{'byteorder'} eq '1234' || $Config{'byteorder'} eq '4321'; + return 0; +} diff --git a/ext/Digest/MD5/t/align.t b/ext/Digest/MD5/t/align.t index 4176062415..e9660f3914 100644 --- a/ext/Digest/MD5/t/align.t +++ b/ext/Digest/MD5/t/align.t @@ -1,6 +1,8 @@ BEGIN { - chdir 't' if -d 't'; - @INC = '../lib'; + if ($ENV{PERL_CORE}) { + chdir 't' if -d 't'; + @INC = '../lib'; + } } # Test that md5 works on unaligned memory blocks diff --git a/ext/Digest/MD5/t/files.t b/ext/Digest/MD5/t/files.t index bf8aa0684e..073bada144 100644 --- a/ext/Digest/MD5/t/files.t +++ b/ext/Digest/MD5/t/files.t @@ -10,11 +10,6 @@ print "1..5\n"; use strict; use Digest::MD5 qw(md5 md5_hex md5_base64); -# -# This is the output of: 'md5sum Changes README MD5.pm MD5.xs rfc1321.txt' -# -my $EXPECT; - # To update the EBCDIC section even on a Latin 1 platform, # run this script with $ENV{EBCDIC_MD5SUM} set to a true value. # (You'll need to have Perl 5.7.3 or later, to have the Encode installed.) @@ -22,27 +17,29 @@ my $EXPECT; # also have the $ENV{PERL_CORE} set to a true value.) # Similarly, to update MacOS section, run with $ENV{MAC_MD5SUM} set. +my $EXPECT; if (ord "A" == 193) { # EBCDIC $EXPECT = <<EOT; -b362148b17a451f0d81e0ebb2487756e Changes +36158997c99f2e1396ee40ddc4634a40 Changes 5a591a47e8c40fe4b78c744111511c45 README -3157e2d2e27dacddea7c54efddc32520 MD5.pm +770a5ef28ab15e66355639f21152afb0 MD5.pm 4850753428db9422e8e5f97b401d5a13 MD5.xs 276da0aa4e9a08b7fe09430c9c5690aa rfc1321.txt EOT } elsif ("\n" eq "\015") { # MacOS $EXPECT = <<EOT; -cc90a85f89b397341f97c9279640fbf5 Changes -127952946201e6afc19eb41250c56871 README -d87ec77c963d27198b7427156167a5b3 MD5.pm -5be7049479ea47d7c257dabcae835720 MD5.xs -f9a35714ee1d1d0c5a3a80f4dbea956a rfc1321.txt +e68b13fe9edf36fe13551bf410b7a745 Changes +3519f3d02c7c91158f732f0f00064657 README +4113db8afad83eb7c01f1bf2c53e66ee MD5.pm +1be293491bba726810f8e87671ee0328 MD5.xs +754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt EOT } else { + # This is the output of: 'md5sum Changes README MD5.pm MD5.xs rfc1321.txt' $EXPECT = <<EOT; -0106b67df0dbf9f4d65e9fc04907745b Changes +e68b13fe9edf36fe13551bf410b7a745 Changes 3519f3d02c7c91158f732f0f00064657 README -88c35ca46c7e8069fb5ae00c091c98d6 MD5.pm +4113db8afad83eb7c01f1bf2c53e66ee MD5.pm 1be293491bba726810f8e87671ee0328 MD5.xs 754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt EOT @@ -187,8 +184,8 @@ sub cat_file local $/; # slurp open(FILE, $file) or die "Can't open $file: $!"; - # For PerlIO (Perl 5.8.0 and later) in case of UTF-8 locales. - eval { binmode(FILE, ":bytes"); }; + # For PerlIO in case of UTF-8 locales. + eval 'binmode(FILE, ":bytes")' if $] >= 5.008; my $tmp = <FILE>; close(FILE); |