Update for ext/Digest/MD5/
[p5sagit/p5-mst-13.2.git] / ext / Digest / MD5 / MD5.pm
index 7a11df9..08e616e 100644 (file)
@@ -3,7 +3,7 @@ package Digest::MD5;
 use strict;
 use vars qw($VERSION @ISA @EXPORT_OK);
 
-$VERSION = '2.13';
+$VERSION = '2.21';  # $Date: 2002/12/28 05:30:03 $
 
 require Exporter;
 *import = \&Exporter::import;
@@ -16,11 +16,18 @@ eval {
     Digest::MD5->bootstrap($VERSION);
 };
 if ($@) {
-    # Try to load the pure perl version
-    require Digest::Perl::MD5;
-
-    Digest::Perl::MD5->import(qw(md5 md5_hex md5_base64));
-    push(@ISA, "Digest::Perl::MD5");  # make OO interface work
+    my $olderr = $@;
+    eval {
+       # Try to load the pure perl version
+       require Digest::Perl::MD5;
+
+       Digest::Perl::MD5->import(qw(md5 md5_hex md5_base64));
+       push(@ISA, "Digest::Perl::MD5");  # make OO interface work
+    };
+    if ($@) {
+       # restore the original error
+       die $olderr;
+    }
 }
 else {
     *reset = \&new;
@@ -88,6 +95,10 @@ Same as md5(), but will return the digest in hexadecimal form.
 
 Same as md5(), but will return the digest as a base64 encoded string.
 
+The base64 encoded string returned is not padded to be a multiple of 4
+bytes long.  If you want interoperability with other base64 encoded
+md5 digests you might want to append the string "==" to the result.
+
 =back
 
 =head1 METHODS
@@ -102,7 +113,7 @@ The constructor returns a new C<Digest::MD5> object which encapsulate
 the state of the MD5 message-digest algorithm.  You can add data to
 the object and finally ask for the digest.
 
-If called as a instance method (i.e. $md5->new) it will just reset the
+If called as an instance method (i.e. $md5->new) it will just reset the
 state the object to the state of a newly created object.  No new
 object is created in this case.
 
@@ -142,6 +153,10 @@ Same as $md5->digest, but will return the digest in hexadecimal form.
 Same as $md5->digest, but will return the digest as a base64 encoded
 string.
 
+The base64 encoded string returned is not padded to be a multiple of 4
+bytes long.  If you want interoperability with other base64 encoded
+md5 digests you might want to append the string "==" to the result.
+
 =back
 
 
@@ -199,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>,
@@ -215,7 +253,7 @@ RFC 1321
 This library is free software; you can redistribute it and/or
 modify it under the same terms as Perl itself.
 
- Copyright 1998-2000 Gisle Aas.
+ Copyright 1998-2002 Gisle Aas.
  Copyright 1995-1996 Neil Winton.
  Copyright 1991-1992 RSA Data Security, Inc.