From: Rafael Garcia-Suarez Date: Fri, 4 Feb 2005 10:41:43 +0000 (+0000) Subject: Upgrade to Digest 1.10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a9acc3567ea7c266e6edabba11e4855b4a1676ed;p=p5sagit%2Fp5-mst-13.2.git Upgrade to Digest 1.10 p4raw-id: //depot/perl@23928 --- diff --git a/MANIFEST b/MANIFEST index b71425f..4389195 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1256,10 +1256,13 @@ lib/Devel/SelfStubber.pm Generate stubs for SelfLoader.pm lib/Devel/SelfStubber.t See if Devel::SelfStubber works lib/diagnostics.pm Print verbose diagnostics lib/diagnostics.t See if diagnostics.pm works +lib/Digest/Changes Digest changelog lib/Digest/base.pm Digest extensions +lib/Digest/file.pm Digest extensions lib/Digest.pm Digest extensions lib/Digest/t/base.t See if Digest extensions work lib/Digest/t/digest.t See if Digest extensions work +lib/Digest/t/file.t See if Digest extensions work lib/DirHandle.pm like FileHandle only for directories lib/DirHandle.t See if DirHandle works lib/dotsh.pl Code to "dot" in a shell script diff --git a/lib/Digest.pm b/lib/Digest.pm index 0cbc417..41cee70 100644 --- a/lib/Digest.pm +++ b/lib/Digest.pm @@ -3,7 +3,7 @@ package Digest; use strict; use vars qw($VERSION %MMAP $AUTOLOAD); -$VERSION = "1.08"; +$VERSION = "1.10"; %MMAP = ( "SHA-1" => ["Digest::SHA1", ["Digest::SHA", 1], ["Digest::SHA2", 1]], diff --git a/lib/Digest/Changes b/lib/Digest/Changes new file mode 100644 index 0000000..d4b508a --- /dev/null +++ b/lib/Digest/Changes @@ -0,0 +1,109 @@ +2004-11-08 Gisle Aas + + Release 1.10 + + Added Digest::file module which provide convenience functions + that calculate digests of files. + + + +2004-11-05 Gisle Aas + + Release 1.09 + + Fix trivial documentation typo. + + + +2004-04-29 Gisle Aas + + Release 1.08 + + Make Digest->new("CRC-16"), Digest->new("CRC-32") and + Digest->new("CRC-CCITT") work. + Patch by Oliver Maul . + + + +2004-04-25 Gisle Aas + + Release 1.07 + + Updated benchmark. + + + +2004-04-01 Gisle Aas + + Release 1.06 + + Added MIME::Base64 dependency. + + Minor doc tweak. + + + +2003-12-01 Gisle Aas + + Release 1.05 + + Drop Digest::MD5 dependency. Avoids circular dependency + now that Digest::MD5 depend on this package to inherit + Digest::base. + + Included a section about digest speed with benchmark + results for some implementations of this API. + + + +2003-11-29 Gisle Aas + + Release 1.04 + + Doc tweaks to unconfuse search.cpan.org. + + + +2003-11-28 Gisle Aas + + Release 1.03 + + Added add_bits() method as requested by the + Digest::SHA author Mark Shelor. + + Added Digest::base class that Digest implementations + can use to get default implementations of addfile(), + add_bits(), hexdigest() and b64digest(). + + Digest->new("SHA-256") and similar should work now + given that you have either Digest::SHA or Digest::SHA2 + installed. + + + +2003-01-18 Gisle Aas + + Release 1.02 + + Sync up with version bundled with perl-5.8. + Patch by Jarkko Hietaniemi . + + Override INSTALLDIRS for 5.8 as suggested by + Guido Ostkamp . + + + +2003-01-04 Gisle Aas + + Release 1.01 + + Document the clone() method. + + + +2001-03-13 Gisle Aas + + Release 1.00 + + Broken out of the Digest-MD5-2.12 distribution and made into + a separate dist. diff --git a/lib/Digest/base.pm b/lib/Digest/base.pm index df9408f..cb336c2 100644 --- a/lib/Digest/base.pm +++ b/lib/Digest/base.pm @@ -72,7 +72,7 @@ __END__ Digest::base - Digest base class -=head1 SYNPOSIS +=head1 SYNOPSIS package Digest::Foo; use base 'Digest::base'; diff --git a/lib/Digest/file.pm b/lib/Digest/file.pm new file mode 100644 index 0000000..2836608 --- /dev/null +++ b/lib/Digest/file.pm @@ -0,0 +1,85 @@ +package Digest::file; + +use strict; + +use Exporter (); +use Carp qw(croak); +use Digest (); + +use vars qw($VERSION @ISA @EXPORT_OK); + +$VERSION = "0.01"; +@ISA = qw(Exporter); +@EXPORT_OK = qw(digest_file_ctx digest_file digest_file_hex digest_file_base64); + +sub digest_file_ctx { + my $file = shift; + croak("No digest algorithm specified") unless @_; + local *F; + open(F, $file) || croak("Can't open '$file': $!"); + binmode(F); + my $ctx = Digest->new(@_); + $ctx->addfile(*F); + close(F); + return $ctx; +} + +sub digest_file { + digest_file_ctx(@_)->digest; +} + +sub digest_file_hex { + digest_file_ctx(@_)->hexdigest; +} + +sub digest_file_base64 { + digest_file_ctx(@_)->b64digest; +} + +1; + +__END__ + +=head1 NAME + +Digest::file - Calculate digests of files + +=head1 SYNOPSIS + + # Poor mans "md5sum" command + use Digest::file qw(digest_file_hex); + for (@ARGV) { + print digest_file_hex($_, "MD5"), " $_\n";e + } + +=head1 DESCRIPTION + +This module provide 3 convenience functions to calculate the digest +of files. The following functions are provided: + +=over + +=item digest_file( $file, $algorithm, [$arg,...] ) + +This function will calculate and return the binary digest of the bytes +of the given file. The function will croak if it fails to open or +read the file. + +The $algorithm is a string like "MD2", "MD5", "SHA-1", "SHA-512". +Additional arguments are passed to the constructor for the +implementation of the given algorithm. + +=item digest_file_hex( $file, $algorithm, [$arg,...] ) + +Same as digest_file(), but return the digest in hex form. + +=item digest_file_base64( $file, $algorithm, [$arg,...] ) + +Same as digest_file(), but return the digest as a base64 encoded +string. + +=back + +=head1 SEE ALSO + +L diff --git a/lib/Digest/t/file.t b/lib/Digest/t/file.t new file mode 100644 index 0000000..2184ac2 --- /dev/null +++ b/lib/Digest/t/file.t @@ -0,0 +1,46 @@ +#!perl -w + +use Test qw(plan ok); +plan tests => 5; + +{ + package Digest::Foo; + require Digest::base; + use vars qw(@ISA $VERSION); + @ISA = qw(Digest::base); + + sub new { + my $class = shift; + my $str = ""; + bless \$str, $class; + } + + sub add { + my $self = shift; + $$self .= join("", @_); + return $self; + } + + sub digest { + my $self = shift; + return sprintf "%04d", length($$self); + } +} + +use Digest::file qw(digest_file digest_file_hex digest_file_base64); + +my $file = "test-$$"; +die if -f $file; +open(F, ">$file") || die "Can't create '$file': $!"; +binmode(F); +print F "foo\0\n"; +close(F) || die "Can't write '$file': $!"; + +ok(digest_file($file, "Foo"), "0005"); +ok(digest_file_hex($file, "Foo"), "30303035"); +ok(digest_file_base64($file, "Foo"), "MDAwNQ"); + +unlink($file) || warn "Can't unlink '$file': $!"; + +ok(eval { digest_file("not-there.txt", "Foo") }, undef); +ok($@);