#!/usr/bin/perl -w # $Id: esha1sum,v 1.2 2002/02/28 22:02:04 jason Exp jason $ # This is like md5sum(1), but produces SHA-1 hashes. sha(1) is similar, # but this supports -c (coming soon) and also reports file sizes (for regular # files). Note that this is stricter than sha(1) (and md5sum(1)) about # opening files (which may be a good thing). # FUTURE: Add switches to parse digest(1), openssl(1), gpg(1), and other # formats when using -c? Output MD5 and/or RIPEMD160 hashes # as well, based on $0 and/or switches? use Getopt::Std; use Digest::SHA1; require "flush.pl"; #%opts = (); #getopts ('c:', \%opts); #if (defined ($opts{'c'})) { #} while ($#ARGV >= 0) { $file = shift @ARGV; $ctx = Digest::SHA1->new; open (FILE, "< $file") || die "$0: can't open $file for reading: $!\n"; # FUTURE: Read files in chunks so we can use multiple hashes and/or # properly report sizes? $ctx->addfile (*FILE); $size = "-"; # in case this isn't a regular file... $size = tell FILE if (-f $file); close FILE; # FIXME: Support hashing input on stdin? (If you really need this, # try using /dev/stdin, if available.) # tabs - the other whitespace. Use -x in less(1) if the file sizes # are really large or variable. print $ctx->hexdigest, "\t$size\t", $file, "\n"; flush (STDOUT); }