Skip to content

Commit

Permalink
cpan/Digest-MD5 - Update to version 2.59 (fixing previous partial upd…
Browse files Browse the repository at this point in the history
…ate)

2.59 Sat Dec 30 2023
- Remove meaningless const type qualifier to silence HPUX builds.
- remove useless perl 5.6 check
- convert bits.t test to use Test::More
- Update Digest::MD5 Synopsis and Examples. Add `my` to synopsis
- MD5.xs: eliminate C++ guards
  • Loading branch information
karenetheridge committed Oct 6, 2024
1 parent 97cb612 commit d153d61
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 125 deletions.
1 change: 0 additions & 1 deletion Porting/Maintainers.pl
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ package Maintainers;

'Digest::MD5' => {
'DISTRIBUTION' => 'TODDR/Digest-MD5-2.59.tar.gz',
'SYNCINFO' => 'root on Sat Dec 30 21:42:47 2023',
'FILES' => q[cpan/Digest-MD5],
'EXCLUDED' => [ 'rfc1321.txt', 'bin/md5sum.pl' ],
},
Expand Down
52 changes: 25 additions & 27 deletions cpan/Digest-MD5/MD5.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Digest::MD5;
use strict;
use warnings;

our $VERSION = '2.58_01';
our $VERSION = '2.59';

require Exporter;
*import = \&Exporter::import;
Expand All @@ -27,15 +27,15 @@ eval {
if ($@) {
my $olderr = $@;
eval {
# Try to load the pure perl version
require Digest::Perl::MD5;
# Try to load the pure perl version
require Digest::Perl::MD5;

Digest::Perl::MD5->import(qw(md5 md5_hex md5_base64));
unshift(@ISA, "Digest::Perl::MD5"); # make OO interface work
Digest::Perl::MD5->import(qw(md5 md5_hex md5_base64));
unshift(@ISA, "Digest::Perl::MD5"); # make OO interface work
};
if ($@) {
# restore the original error
die $olderr;
# restore the original error
die $olderr;
}
}
else {
Expand All @@ -51,24 +51,24 @@ Digest::MD5 - Perl interface to the MD5 Algorithm
=head1 SYNOPSIS
# Functional style
use Digest::MD5 qw(md5 md5_hex md5_base64);
# Functional style
use Digest::MD5 qw(md5 md5_hex md5_base64);
$digest = md5($data);
$digest = md5_hex($data);
$digest = md5_base64($data);
my $digest = md5($data);
my $digest = md5_hex($data);
my $digest = md5_base64($data);
# OO style
use Digest::MD5;
# OO style
use Digest::MD5;
$ctx = Digest::MD5->new;
my $ctx = Digest::MD5->new;
$ctx->add($data);
$ctx->addfile($file_handle);
$ctx->add($data);
$ctx->addfile($file_handle);
$digest = $ctx->digest;
$digest = $ctx->hexdigest;
$digest = $ctx->b64digest;
$digest = $ctx->digest;
$digest = $ctx->hexdigest;
$digest = $ctx->b64digest;
=head1 DESCRIPTION
Expand Down Expand Up @@ -157,8 +157,8 @@ stream. Example:
my $md5 = Digest::MD5->new;
while (<>) {
$md5->add($_);
print "Line $.: ", $md5->clone->hexdigest, "\n";
$md5->add($_);
print "Line $.: ", $md5->clone->hexdigest, "\n";
}
=item $md5->add($data,...)
Expand Down Expand Up @@ -258,12 +258,10 @@ The above example would print out the message:
The same checksum can also be calculated in OO style:
use Digest::MD5;
$md5 = Digest::MD5->new;
my $md5 = Digest::MD5->new;
$md5->add('foo', 'bar');
$md5->add('baz');
$digest = $md5->hexdigest;
my $digest = $md5->hexdigest;
print "Digest is $digest\n";
With OO style, you can break the message arbitrarily. This means that we
Expand All @@ -278,7 +276,7 @@ This is useful when calculating checksum for files:
open (my $fh, '<', $filename) or die "Can't open '$filename': $!";
binmode($fh);
$md5 = Digest::MD5->new;
my $md5 = Digest::MD5->new;
while (<$fh>) {
$md5->add($_);
}
Expand Down
4 changes: 2 additions & 2 deletions cpan/Digest-MD5/MD5.xs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ static MD5_CTX* get_md5_ctx(pTHX_ SV* sv)

for (mg = SvMAGIC(SvRV(sv)); mg; mg = mg->mg_moremagic) {
if (mg->mg_type == PERL_MAGIC_ext
&& mg->mg_virtual == (const MGVTBL * const)&vtbl_md5) {
&& mg->mg_virtual == (const MGVTBL *)&vtbl_md5) {
return (MD5_CTX *)mg->mg_ptr;
}
}
Expand All @@ -483,7 +483,7 @@ static SV * new_md5_ctx(pTHX_ MD5_CTX *context, const char *klass)
#ifdef USE_ITHREADS
mg =
#endif
sv_magicext(sv, NULL, PERL_MAGIC_ext, (const MGVTBL * const)&vtbl_md5, (const char *)context, 0);
sv_magicext(sv, NULL, PERL_MAGIC_ext, (const MGVTBL *)&vtbl_md5, (const char *)context, 0);

#if defined(USE_ITHREADS) && defined(MGf_DUP)
mg->mg_flags |= MGf_DUP;
Expand Down
189 changes: 94 additions & 95 deletions cpan/Digest-MD5/t/files.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ my $EXPECT;
if (ord "A" == 193) { # EBCDIC
$EXPECT = <<EOT;
0956ffb4f6416082b27d6680b4cf73fc README
3fce99bf3f4df26d65843a6990849df0 MD5.xs
f9d533188a37309320d2805372db0b0e MD5.xs
276da0aa4e9a08b7fe09430c9c5690aa rfc1321.txt
EOT
} else {
# This is the output of: 'md5sum README MD5.xs rfc1321.txt'
$EXPECT = <<EOT;
2f93400875dbb56f36691d5f69f3eba5 README
f8549bd328fa712f4af41430738c285a MD5.xs
f4b5da4e0f19b4c0ab374b7085ed8955 MD5.xs
754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt
EOT
}
Expand All @@ -41,99 +41,99 @@ if ($@) {
}

for (split /^/, $EXPECT) {
my($md5hex, $file) = split ' ';
my $base = $file;
# print "# $base\n";
if ($ENV{PERL_CORE}) {
my($md5hex, $file) = split ' ';
my $base = $file;
# print "# $base\n";
if ($ENV{PERL_CORE}) {
# Don't have these in core.
if ($file eq 'rfc1321.txt' or $file eq 'README') {
print "ok ", ++$testno, " # Skip: PERL_CORE\n";
next;
}
}
# print "# file = $file\n";
unless (-f $file) {
warn "No such file: $file\n";
next;
}
if ($ENV{EBCDIC_MD5SUM}) {
require Encode;
my $data = cat_file($file);
Encode::from_to($data, 'latin1', 'cp1047');
print md5_hex($data), " $base\n";
next;
}
my $md5bin = pack("H*", $md5hex);
my $md5b64;
if ($B64) {
$md5b64 = MIME::Base64::encode($md5bin, "");
chop($md5b64); chop($md5b64); # remove padding
}
my $failed;
my $got;

if (digest_file($file, 'digest') ne $md5bin) {
print "$file: Bad digest\n";
$failed++;
}

if (($got = digest_file($file, 'hexdigest')) ne $md5hex) {
print "$file: Bad hexdigest: got $got expected $md5hex\n";
$failed++;
}

if ($B64 && digest_file($file, 'b64digest') ne $md5b64) {
print "$file: Bad b64digest\n";
$failed++;
}

my $data = cat_file($file);
if (md5($data) ne $md5bin) {
print "$file: md5() failed\n";
$failed++;
}
if (md5_hex($data) ne $md5hex) {
print "$file: md5_hex() failed\n";
$failed++;
}
if ($B64 && md5_base64($data) ne $md5b64) {
print "$file: md5_base64() failed\n";
$failed++;
}

if (Digest::MD5->new->add($data)->digest ne $md5bin) {
print "$file: MD5->new->add(...)->digest failed\n";
$failed++;
}
if (Digest::MD5->new->add($data)->hexdigest ne $md5hex) {
print "$file: MD5->new->add(...)->hexdigest failed\n";
$failed++;
}
if ($B64 && Digest::MD5->new->add($data)->b64digest ne $md5b64) {
print "$file: MD5->new->add(...)->b64digest failed\n";
$failed++;
}

my @data = split //, $data;
if (md5(@data) ne $md5bin) {
print "$file: md5(\@data) failed\n";
$failed++;
}
if (Digest::MD5->new->add(@data)->digest ne $md5bin) {
print "$file: MD5->new->add(\@data)->digest failed\n";
$failed++;
}
my $md5 = Digest::MD5->new;
for (@data) {
$md5->add($_);
}
if ($md5->digest ne $md5bin) {
print "$file: $md5->add()-loop failed\n";
$failed++;
}

print "not " if $failed;
print "ok ", ++$testno, "\n";
if ($file eq 'rfc1321.txt' or $file eq 'README') {
print "ok ", ++$testno, " # Skip: PERL_CORE\n";
next;
}
}
# print "# file = $file\n";
unless (-f $file) {
warn "No such file: $file\n";
next;
}
if ($ENV{EBCDIC_MD5SUM}) {
require Encode;
my $data = cat_file($file);
Encode::from_to($data, 'latin1', 'cp1047');
print md5_hex($data), " $base\n";
next;
}
my $md5bin = pack("H*", $md5hex);
my $md5b64;
if ($B64) {
$md5b64 = MIME::Base64::encode($md5bin, "");
chop($md5b64); chop($md5b64); # remove padding
}
my $failed;
my $got;

if (digest_file($file, 'digest') ne $md5bin) {
print "$file: Bad digest\n";
$failed++;
}

if (($got = digest_file($file, 'hexdigest')) ne $md5hex) {
print "$file: Bad hexdigest: got $got expected $md5hex\n";
$failed++;
}

if ($B64 && digest_file($file, 'b64digest') ne $md5b64) {
print "$file: Bad b64digest\n";
$failed++;
}

my $data = cat_file($file);
if (md5($data) ne $md5bin) {
print "$file: md5() failed\n";
$failed++;
}
if (md5_hex($data) ne $md5hex) {
print "$file: md5_hex() failed\n";
$failed++;
}
if ($B64 && md5_base64($data) ne $md5b64) {
print "$file: md5_base64() failed\n";
$failed++;
}

if (Digest::MD5->new->add($data)->digest ne $md5bin) {
print "$file: MD5->new->add(...)->digest failed\n";
$failed++;
}
if (Digest::MD5->new->add($data)->hexdigest ne $md5hex) {
print "$file: MD5->new->add(...)->hexdigest failed\n";
$failed++;
}
if ($B64 && Digest::MD5->new->add($data)->b64digest ne $md5b64) {
print "$file: MD5->new->add(...)->b64digest failed\n";
$failed++;
}

my @data = split //, $data;
if (md5(@data) ne $md5bin) {
print "$file: md5(\@data) failed\n";
$failed++;
}
if (Digest::MD5->new->add(@data)->digest ne $md5bin) {
print "$file: MD5->new->add(\@data)->digest failed\n";
$failed++;
}
my $md5 = Digest::MD5->new;
for (@data) {
$md5->add($_);
}
if ($md5->digest ne $md5bin) {
print "$file: $md5->add()-loop failed\n";
$failed++;
}

print "not " if $failed;
print "ok ", ++$testno, "\n";
}


Expand Down Expand Up @@ -163,4 +163,3 @@ sub cat_file
close(FILE);
$tmp;
}

0 comments on commit d153d61

Please sign in to comment.