Revision history for Perl extension Digest::SHA.
+5.41 Sat Jun 3 01:50:46 MST 2006
+ - corrected addfile
+ -- process $file argument as a filehandle unless passed
+ as a SCALAR (which indicates a file name)
+
+5.40 Fri Jun 2 04:00:30 MST 2006
+ - modified addfile to accept indirect filehandles
+ -- ref. rt.cpan.org #19627 and #19641
+
+5.39 Sun May 28 03:22:24 MST 2006
+ - modified shasum to warn rather than die for file errors
+ -- to follow conventions of GNU sha1sum/md5sum
+
5.38 Thu May 25 02:02:02 MST 2006
- added new capabilities to the "addfile" method
-- now able to accept file names as well as handles
-Digest::SHA version 5.38
+Digest::SHA version 5.41
========================
Digest::SHA is a complete implementation of the NIST Secure Hash
use warnings;
use integer;
-our $VERSION = '5.38_01';
+our $VERSION = '5.41';
require Exporter;
our @ISA = qw(Exporter);
sub Addfile {
my ($self, $file, $mode) = @_;
- if (ref(\$file) eq 'GLOB') { return(_addfile($self, $file)) }
+ return(_addfile($self, $file)) unless ref(\$file) eq 'SCALAR';
$mode = defined($mode) ? $mode : "";
my ($binary, $portable) = map { $_ eq $mode } ("b", "p");
last unless $n2;
$buf1 .= $buf2;
}
- $buf1 =~ s/\015?\015\012/\012/g; # DOS/Windows
- $buf1 =~ s/\015/\012/g; # Apple/MacOS 9
+ $buf1 =~ s/\015?\015\012/\012/g; # DOS/Windows
+ $buf1 =~ s/\015/\012/g; # Apple/MacOS 9
$self->add($buf1);
}
_bail("Read failed") unless defined $n1;
or I/O disciplines are used. To change this, set the optional I<$mode>
argument to one of the following values:
-=over 4
-
-=item B<"b"> read file in binary mode
+ "b" read file in binary mode
-=item B<"p"> use portable mode
-
-=back
+ "p" use portable mode
The "p" mode is handy since it ensures that the digest value of
I<$filename> will be the same when computed on different operating
#!perl -w
- # shasum: filter for computing SHA digests (analogous to md5sum)
+ # shasum: filter for computing SHA digests (analogous to sha1sum)
#
# Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
#
- # Version: 5.38
- # Thu May 25 02:02:02 MST 2006
+ # Version: 5.41
+ # Sat Jun 3 01:50:46 MST 2006
=head1 NAME
use strict;
use Getopt::Long;
-my $VERSION = "5.38";
+my $VERSION = "5.41";
# Try to use Digest::SHA, since it's faster. If not installed,
usage(0)
if $help;
-usage(1, "Ambiguous file mode\n")
+usage(1, "shasum: Ambiguous file mode\n")
if scalar(grep { defined $_ } ($binary, $portable, $text)) > 1;
usage(1, "shasum: --warn option used only when verifying checksums\n")
if $warn && !$check;
$alg = 1 unless $alg;
grep { $_ == $alg } (1, 224, 256, 384, 512)
- or usage(1, "Unrecognized algorithm\n");
+ or usage(1, "shasum: Unrecognized algorithm\n");
# Display version information if requested
sub sumfile {
my $file = shift;
- unless (-e $file) {
- warn "shasum: $file: No such file or directory\n";
+ my $mode = $portable ? 'p' : ($binary ? 'b' : '');
+ my $digest = eval { $module->new($alg)->addfile($file, $mode) };
+ if ($@) {
+ warn "shasum: $file: $!\n";
return;
}
- unless (-r $file) {
- warn "shasum: $file: FAILED open or read\n";
- return;
- }
-
- my $digest = $module->new($alg);
- unless ($digest) {
- warn "shasum: $file: FAILED digest creation\n";
- return;
- }
-
- my $readmode = $portable ? 'p' : ($binary ? 'b' : '');
- $digest->addfile($file, $readmode)->hexdigest;
+ $digest->hexdigest;
}
my ($num_files, $num_checksums) = (0, 0);
my ($fh, $sum, $fname, $rsp);
- die "shasum: $checkfile: No such file or directory\n"
+ die "shasum: $checkfile: $!\n"
unless open($fh, "<$checkfile");
while (<$fh>) {
s/\s+$//;
# Compute and display SHA checksums of requested files
-for my $arg (@ARGV) {
- if (-d $arg) {
- warn "shasum: $arg: Is a directory\n";
- next;
+for my $file (@ARGV) {
+ if (my $digest = sumfile($file)) {
+ print "$digest $modesym", "$file\n";
}
- my $digest = sumfile($arg) or next;
- print "$digest $modesym$arg\n";
}
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.38
- * Thu May 25 02:02:02 MST 2006
+ * Version: 5.41
+ * Sat Jun 3 01:50:46 MST 2006
*
*/
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.38
- * Thu May 25 02:02:02 MST 2006
+ * Version: 5.41
+ * Sat Jun 3 01:50:46 MST 2006
*
*/
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.38
- * Thu May 25 02:02:02 MST 2006
+ * Version: 5.41
+ * Sat Jun 3 01:50:46 MST 2006
*
*/
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.38
- * Thu May 25 02:02:02 MST 2006
+ * Version: 5.41
+ * Sat Jun 3 01:50:46 MST 2006
*
*/
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
);
- plan tests => 5 + scalar(@vec);
+ plan tests => 6 + scalar(@vec);
}
# attempt to use an invalid algorithm, and check for failure
ok($ctx->clone->addfile(*FILE)->hexdigest, $rsp);
close(FILE);
+ # use indirect filehandle
+
+open(my $fh, "<$file");
+binmode($fh);
+ok($ctx->clone->addfile($fh)->hexdigest, $rsp);
+close($fh);
+
# test addfile using file name instead of handle
ok($ctx->addfile($file, "b")->hexdigest, $rsp);