summaryrefslogtreecommitdiff
path: root/cpan
diff options
context:
space:
mode:
authorChris 'BinGOs' Williams <chris@bingosnet.co.uk>2011-12-14 12:09:12 +0000
committerChris 'BinGOs' Williams <chris@bingosnet.co.uk>2011-12-14 12:09:12 +0000
commite39652eac43f367c8dc80418cc0c858496c83f83 (patch)
treed706a009e77d10c7747d6d4843001ad4dcaa52f1 /cpan
parente46b6a3298faa41ef29068aa0bdd9f93fe720887 (diff)
downloadperl-e39652eac43f367c8dc80418cc0c858496c83f83.tar.gz
Update Digest-SHA to CPAN version 5.70
[DELTA] 5.70 Wed Dec 14 02:32:10 MST 2011 - added BITS mode to addfile method and shasum -- partial-byte inputs now possible via files/STDIN -- allows shasum to check all 8074 NIST Msg vectors -- previously required special programming
Diffstat (limited to 'cpan')
-rw-r--r--cpan/Digest-SHA/Changes6
-rw-r--r--cpan/Digest-SHA/README2
-rw-r--r--cpan/Digest-SHA/lib/Digest/SHA.pm39
-rw-r--r--cpan/Digest-SHA/shasum35
-rw-r--r--cpan/Digest-SHA/src/hmac.c4
-rw-r--r--cpan/Digest-SHA/src/hmac.h4
-rw-r--r--cpan/Digest-SHA/src/sha.c4
-rw-r--r--cpan/Digest-SHA/src/sha.h4
-rw-r--r--cpan/Digest-SHA/t/methods.t21
9 files changed, 83 insertions, 36 deletions
diff --git a/cpan/Digest-SHA/Changes b/cpan/Digest-SHA/Changes
index b6c056f0ac..56d42b5202 100644
--- a/cpan/Digest-SHA/Changes
+++ b/cpan/Digest-SHA/Changes
@@ -1,5 +1,11 @@
Revision history for Perl extension Digest::SHA.
+5.70 Wed Dec 14 02:32:10 MST 2011
+ - added BITS mode to addfile method and shasum
+ -- partial-byte inputs now possible via files/STDIN
+ -- allows shasum to check all 8074 NIST Msg vectors
+ -- previously required special programming
+
5.63 Tue Nov 8 02:36:42 MST 2011
- added code to allow very large data inputs all at once
-- previously limited to several hundred MB at a time
diff --git a/cpan/Digest-SHA/README b/cpan/Digest-SHA/README
index 8498bb34fb..a8703a8970 100644
--- a/cpan/Digest-SHA/README
+++ b/cpan/Digest-SHA/README
@@ -1,4 +1,4 @@
-Digest::SHA version 5.63
+Digest::SHA version 5.70
========================
Digest::SHA is a complete implementation of the NIST Secure Hash
diff --git a/cpan/Digest-SHA/lib/Digest/SHA.pm b/cpan/Digest-SHA/lib/Digest/SHA.pm
index ce652b63d1..0f6338b2d0 100644
--- a/cpan/Digest-SHA/lib/Digest/SHA.pm
+++ b/cpan/Digest-SHA/lib/Digest/SHA.pm
@@ -7,7 +7,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
use Fcntl;
use integer;
-$VERSION = '5.63';
+$VERSION = '5.70';
require Exporter;
require DynaLoader;
@@ -81,6 +81,7 @@ sub add_bits {
$nbits = length($data);
$data = pack("B*", $data);
}
+ $nbits = length($data) * 8 if $nbits > length($data) * 8;
shawrite($data, $nbits, $$self);
return($self);
}
@@ -112,7 +113,7 @@ sub Addfile {
return(_addfile($self, $file)) unless ref(\$file) eq 'SCALAR';
$mode = defined($mode) ? $mode : "";
- my ($binary, $portable) = map { $_ eq $mode } ("b", "p");
+ my ($binary, $portable, $BITS) = map { $_ eq $mode } ("b", "p", "0");
## Always interpret "-" to mean STDIN; otherwise use
## sysopen to handle full range of POSIX file names
@@ -120,8 +121,19 @@ sub Addfile {
$file eq '-' and open(FH, '< -')
or sysopen(FH, $file, O_RDONLY)
or _bail('Open failed');
- binmode(FH) if $binary || $portable;
+ if ($BITS) {
+ my ($n, $buf) = (0, "");
+ while (($n = read(FH, $buf, 4096))) {
+ $buf =~ s/[^01]//g;
+ $self->add_bits($buf);
+ }
+ _bail("Read failed") unless defined $n;
+ close(FH);
+ return($self);
+ }
+
+ binmode(FH) if $binary || $portable;
unless ($portable && -T $file) {
$self->_addfile(*FH);
close(FH);
@@ -511,15 +523,20 @@ argument to one of the following values:
"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
-systems. It accomplishes this by internally translating all newlines in
-text files to UNIX format before calculating the digest. Binary files
-are read in raw mode with no translation whatsoever.
+ "0" use BITS mode
+
+The "p" mode ensures that the digest value of I<$filename> will be the
+same when computed on different operating systems. It accomplishes
+this by internally translating all newlines in text files to UNIX format
+before calculating the digest. Binary files are read in raw mode with
+no translation whatsoever.
-For a fuller discussion of newline formats, refer to CPAN module
-L<File::LocalizeNewlines>. Its "universal line separator" regex forms
-the basis of I<addfile>'s portable mode processing.
+The BITS mode ("0") interprets the contents of I<$filename> as a logical
+stream of bits, where each ASCII '0' or '1' character represents a 0 or
+1 bit, respectively. All other characters are ignored. This provides
+a convenient way to calculate the digest values of partial-byte data by
+using files, rather than having to write programs using the I<add_bits>
+method.
=item B<dump($filename)>
diff --git a/cpan/Digest-SHA/shasum b/cpan/Digest-SHA/shasum
index 4dd2572fca..344e8e1af6 100644
--- a/cpan/Digest-SHA/shasum
+++ b/cpan/Digest-SHA/shasum
@@ -4,8 +4,8 @@
##
## Copyright (C) 2003-2011 Mark Shelor, All Rights Reserved
##
- ## Version: 5.63
- ## Tue Nov 8 02:36:42 MST 2011
+ ## Version: 5.70
+ ## Wed Dec 14 02:32:10 MST 2011
## shasum SYNOPSIS adapted from GNU Coreutils sha1sum.
## Include an "-a" option for algorithm selection, and a
@@ -26,8 +26,12 @@ shasum - Print or Check SHA Checksums
-a, --algorithm 1 (default), 224, 256, 384, 512, 512224, 512256
-b, --binary read in binary mode
-c, --check read SHA sums from the FILEs and check them
- -p, --portable read files in portable mode
+ -p, --portable read in portable mode
produces same digest on Windows/Unix/Mac
+ -0, --01 read in BITS mode
+ ASCII '0' interpreted as 0-bit,
+ ASCII '1' interpreted as 1-bit,
+ all other characters ignored
-t, --text read in text mode (default)
The following two options are useful only when verifying checksums:
@@ -45,7 +49,7 @@ shasum - Print or Check SHA Checksums
The sums are computed as described in FIPS-180-4. When checking, the
input should be a former output of this program. The default mode is to
print a line with checksum, a character indicating type (`*' for binary,
- ` ' for text, `?' for portable), and name for each FILE.
+ ` ' for text, `?' for portable, `^' for BITS), and name for each FILE.
Report shasum bugs to mshelor@cpan.org
@@ -55,8 +59,8 @@ Running I<shasum> is often the quickest way to compute SHA message
digests. The user simply feeds data to the script through files or
standard input, and then collects the results from standard output.
-The following command shows how easy it is to compute digests for typical
-inputs such as the NIST test vector "abc":
+The following command shows how to compute digests for typical inputs
+such as the NIST test vector "abc":
perl -e "print qq(abc)" | shasum
@@ -85,7 +89,7 @@ use strict;
use Fcntl;
use Getopt::Long;
-my $VERSION = "5.63";
+my $VERSION = "5.70";
## Try to use Digest::SHA. If not installed, use the slower
@@ -127,7 +131,7 @@ select((select(STDERR), $| = 1)[0]);
## Collect options from command line
my ($alg, $binary, $check, $text, $status, $warn, $help, $version);
-my ($portable);
+my ($portable, $BITS);
eval { Getopt::Long::Configure ("bundling") };
GetOptions(
@@ -135,7 +139,8 @@ GetOptions(
't|text' => \$text, 'a|algorithm=i' => \$alg,
's|status' => \$status, 'w|warn' => \$warn,
'h|help' => \$help, 'v|version' => \$version,
- 'p|portable' => \$portable
+ 'p|portable' => \$portable,
+ '0|01' => \$BITS
) or usage(1, "");
@@ -144,7 +149,7 @@ GetOptions(
usage(0)
if $help;
usage(1, "shasum: Ambiguous file mode\n")
- if scalar(grep { defined $_ } ($binary, $portable, $text)) > 1;
+ if scalar(grep {defined $_} ($binary, $portable, $text, $BITS)) > 1;
usage(1, "shasum: --warn option used only when verifying checksums\n")
if $warn && !$check;
usage(1, "shasum: --status option used only when verifying checksums\n")
@@ -174,7 +179,7 @@ if ($version) {
my $isDOSish = ($^O =~ /^(MSWin\d\d|os2|dos|mint|cygwin)$/);
if ($isDOSish) { $binary = 1 unless $text || $portable }
-my $modesym = $binary ? '*' : ($portable ? '?' : ' ');
+my $modesym = $binary ? '*' : ($portable ? '?' : ($BITS ? '^' : ' '));
## Read from STDIN (-) if no files listed on command line
@@ -187,7 +192,7 @@ my $modesym = $binary ? '*' : ($portable ? '?' : ' ');
sub sumfile {
my $file = shift;
- my $mode = $portable ? 'p' : ($binary ? 'b' : '');
+ my $mode = $portable ? 'p' : ($binary ? 'b' : ($BITS ? '0' : ''));
my $digest = eval { $module->new($alg)->addfile($file, $mode) };
if ($@) { warn "shasum: $file: $!\n"; return }
$digest->hexdigest;
@@ -230,7 +235,7 @@ sub verify {
next if /^#/; s/\n$//; s/^[ \t]+//; $num_lines++;
$bslash = s/^\\//;
($sum, $modesym, $fname) =
- /^([\da-fA-F]+)[ \t]([ *?])([^\0]*)/;
+ /^([\da-fA-F]+)[ \t]([ *?^])([^\0]*)/;
$alg = defined $sum ? $len2alg{length($sum)} : undef;
$fname = unescape($fname) if defined $fname && $bslash;
if (grep { ! defined $_ } ($alg, $sum, $modesym, $fname)) {
@@ -242,8 +247,8 @@ sub verify {
}
$fname =~ s/\r$// unless -e $fname;
$rsp = "$fname: "; $num_files++;
- ($binary, $portable, $text) =
- map { $_ eq $modesym } ('*', '?', ' ');
+ ($binary, $portable, $text, $BITS) =
+ map { $_ eq $modesym } ('*', '?', ' ', '^');
unless ($digest = sumfile($fname)) {
$rsp .= "FAILED open or read\n";
$err = 1; $read_errs++;
diff --git a/cpan/Digest-SHA/src/hmac.c b/cpan/Digest-SHA/src/hmac.c
index 35fd887f76..c820bc5d56 100644
--- a/cpan/Digest-SHA/src/hmac.c
+++ b/cpan/Digest-SHA/src/hmac.c
@@ -5,8 +5,8 @@
*
* Copyright (C) 2003-2011 Mark Shelor, All Rights Reserved
*
- * Version: 5.63
- * Tue Nov 8 02:36:42 MST 2011
+ * Version: 5.70
+ * Wed Dec 14 02:32:10 MST 2011
*
*/
diff --git a/cpan/Digest-SHA/src/hmac.h b/cpan/Digest-SHA/src/hmac.h
index d08bd9a45c..757c05208c 100644
--- a/cpan/Digest-SHA/src/hmac.h
+++ b/cpan/Digest-SHA/src/hmac.h
@@ -5,8 +5,8 @@
*
* Copyright (C) 2003-2011 Mark Shelor, All Rights Reserved
*
- * Version: 5.63
- * Tue Nov 8 02:36:42 MST 2011
+ * Version: 5.70
+ * Wed Dec 14 02:32:10 MST 2011
*
*/
diff --git a/cpan/Digest-SHA/src/sha.c b/cpan/Digest-SHA/src/sha.c
index 2cd0fa319e..cfec4dbde5 100644
--- a/cpan/Digest-SHA/src/sha.c
+++ b/cpan/Digest-SHA/src/sha.c
@@ -5,8 +5,8 @@
*
* Copyright (C) 2003-2011 Mark Shelor, All Rights Reserved
*
- * Version: 5.63
- * Tue Nov 8 02:36:42 MST 2011
+ * Version: 5.70
+ * Wed Dec 14 02:32:10 MST 2011
*
*/
diff --git a/cpan/Digest-SHA/src/sha.h b/cpan/Digest-SHA/src/sha.h
index ed260c6cfe..048044bf50 100644
--- a/cpan/Digest-SHA/src/sha.h
+++ b/cpan/Digest-SHA/src/sha.h
@@ -5,8 +5,8 @@
*
* Copyright (C) 2003-2011 Mark Shelor, All Rights Reserved
*
- * Version: 5.63
- * Tue Nov 8 02:36:42 MST 2011
+ * Version: 5.70
+ * Wed Dec 14 02:32:10 MST 2011
*
*/
diff --git a/cpan/Digest-SHA/t/methods.t b/cpan/Digest-SHA/t/methods.t
index 6ed690b5d4..f7cecd20a2 100644
--- a/cpan/Digest-SHA/t/methods.t
+++ b/cpan/Digest-SHA/t/methods.t
@@ -21,7 +21,7 @@ my @out = (
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
);
-my $numtests = 6 + scalar @out;
+my $numtests = 8 + scalar @out;
print "1..$numtests\n";
# attempt to use an invalid algorithm, and check for failure
@@ -100,3 +100,22 @@ $fh->close;
print "not " unless $sha->new(1)->addfile($tempfile, "p")->hexdigest eq
"d449e19c1b0b0c191294c8dc9fa2e4a6ff77fc51";
print "ok ", $testnum++, "\n";
+
+ # test addfile BITS mode
+
+$fh = FileHandle->new($tempfile, "w");
+print $fh "0100010"; # using NIST 7-bit test vector
+$fh->close;
+
+print "not " unless $sha->new(1)->addfile($tempfile, "0")->hexdigest eq
+ "04f31807151181ad0db278a1660526b0aeef64c2";
+print "ok ", $testnum++, "\n";
+
+$fh = FileHandle->new($tempfile, "w");
+binmode($fh);
+print $fh map(chr, (0..127)); # this is actually NIST 2-bit test
+$fh->close; # vector "01" (other chars ignored)
+
+print "not " unless $sha->new(1)->addfile($tempfile, "0")->hexdigest eq
+ "ec6b39952e1a3ec3ab3507185cf756181c84bbe2";
+print "ok ", $testnum++, "\n";