Revision history for Perl extension Digest::SHA.
+5.37 Mon May 8 04:30:09 MST 2006
+ - modified shasum to avoid file slurping (ref. sub sumfile)
+ - improved error handling of checksum files in shasum
+ -- to better mimic the behavior of md5sum
+ - refined line-break regex in shasum (ref. sub sumfile)
+ -- catches multiple CR's preceding LF
+ thanks to Gisle Aas for suggested patch
+ - changed loop vars to signed int's in shadump (ref. src/sha.c)
+ -- to prevent type mismatch warnings
+
5.36 Mon May 8 01:38:36 MST 2006
- fixed the "portable" option in shasum
-- normalize line-breaks in text files only
#
# Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
#
- # Version: 5.36
- # Mon May 8 01:38:36 MST 2006
+ # Version: 5.37
+ # Mon May 8 04:30:09 MST 2006
=head1 NAME
use strict;
use Getopt::Long;
-my $VERSION = "5.36";
+my $VERSION = "5.37";
# Try to use Digest::SHA, since it's faster. If not installed,
# sumfile($file): computes SHA digest of $file
sub sumfile {
- my($file) = @_;
- my($fh, $digest);
+ my $file = shift;
- unless (open($fh, "<$file")) {
- print STDERR "shasum: $file: No such file or directory\n";
- return;
- }
- binmode($fh) if $binary || $portable;
-
- local $/;
- my $buf = <$fh>;
- close($fh);
+ local *F;
+ return unless open(F, "<$file");
+ binmode(F) if $binary || $portable;
+ my $digest = $module->new($alg);
if ($portable && -T $file) {
- $buf =~ s/\015\012/\012/g;
- $buf =~ s/\015/\012/g;
+ local $/ = \4096;
+ while (defined (my $rec = <F>)) {
+ while (substr($rec, -1) eq "\015") {
+ defined (my $extra = <F>) or last;
+ $rec .= $extra;
+ }
+ $rec =~ s/\015+\012/\012/g;
+ $rec =~ s/\015/\012/g;
+ $digest->add($rec);
+ }
}
+ else { $digest->addfile(*F) }
+ close(F);
- $digest = $module->new($alg)->add($buf)->hexdigest;
+ $digest->hexdigest;
}
while (<$fh>) {
s/\s+$//;
($sum, $mode, $fname) = /^(\S+) (.)(.*)$/;
+ unless (-e $fname) {
+ warn "shasum: $fname: No such file or directory\n";
+ next;
+ }
($binary, $portable, $text) =
map { $_ eq $mode } ('*', '?', ' ');
unless ($alg = $len2alg{length($sum)}) {
- print STDERR "shasum: $checkfile: $.: improperly ",
- "formatted SHA checksum line\n" if $warn;
+ warn("shasum: $checkfile: $.: improperly " .
+ "formatted SHA checksum line\n") if $warn;
next;
}
$rsp = "$fname: ";
- if (lc($sum) eq sumfile($fname)) { $rsp .= "OK\n" }
- else { $rsp .= "FAILED\n"; $err = 1 }
+ unless (my $digest = sumfile($fname)) {
+ $rsp .= "FAILED open or read\n";
+ $err = 1;
+ }
+ else {
+ if (lc($sum) eq $digest) { $rsp .= "OK\n" }
+ else { $rsp .= "FAILED\n"; $err = 1 }
+ }
print $rsp unless $status;
}
close($fh);
# Compute and display SHA checksums of requested files
-for (@ARGV) {
- if (-d $_) {
- print STDERR "shasum: $_: Is a directory\n";
+for my $arg (@ARGV) {
+ if (-d $arg) {
+ print STDERR "shasum: $arg: Is a directory\n";
next;
}
- next unless my $digest = sumfile($_);
- print "$digest $mode", "$_\n";
+ next unless my $digest = sumfile($arg);
+ print "$digest $mode", "$arg\n";
}
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.36
- * Mon May 8 01:38:36 MST 2006
+ * Version: 5.37
+ * Mon May 8 04:30:09 MST 2006
*
*/
char *file;
SHA *s;
{
- unsigned int i, j;
+ int i, j;
SHA_FILE *f;
UCHR *p = shadigest(s);
for (j = 0; j < (UINT) (s->alg <= 256 ? 4 : 8); j++)
SHA_fprintf(f, "%s%02x", j==0 ? ":" : "", *p++);
SHA_fprintf(f, "\nblock");
- for (i = 0; i < s->blocksize>>3; i++)
+ for (i = 0; i < (int) (s->blocksize >> 3); i++)
SHA_fprintf(f, ":%02x", s->block[i]);
SHA_fprintf(f, "\nblockcnt:%u\n", s->blockcnt);
SHA_fprintf(f, "lenhh:%lu\nlenhl:%lu\nlenlh:%lu\nlenll:%lu\n",