Update Digest-SHA to CPAN version 5.70
authorChris 'BinGOs' Williams <chris@bingosnet.co.uk>
Wed, 14 Dec 2011 12:09:12 +0000 (12:09 +0000)
committerChris 'BinGOs' Williams <chris@bingosnet.co.uk>
Wed, 14 Dec 2011 12:09:12 +0000 (12:09 +0000)
  [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

Porting/Maintainers.pl
cpan/Digest-SHA/Changes
cpan/Digest-SHA/README
cpan/Digest-SHA/lib/Digest/SHA.pm
cpan/Digest-SHA/shasum
cpan/Digest-SHA/src/hmac.c
cpan/Digest-SHA/src/hmac.h
cpan/Digest-SHA/src/sha.c
cpan/Digest-SHA/src/sha.h
cpan/Digest-SHA/t/methods.t
pod/perldelta.pod

index 134b9fc..d63acda 100755 (executable)
@@ -598,8 +598,8 @@ use File::Glob qw(:case);
     'Digest::SHA' =>
        {
        'MAINTAINER'    => 'mshelor',
-       'DISTRIBUTION'  => 'MSHELOR/Digest-SHA-5.63.tar.gz',
-       'FILES'         => q[cpan/Digest-SHA],
+       'DISTRIBUTION'  => 'MSHELOR/Digest-SHA-5.70.tar.gz',
+       'FILES'     => q[cpan/Digest-SHA],
        'EXCLUDED'      => [ qw{t/pod.t t/podcover.t examples/dups} ],
        'UPSTREAM'      => 'cpan',
        },
index b6c056f..56d42b5 100644 (file)
@@ -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
index 8498bb3..a8703a8 100644 (file)
@@ -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
index ce652b6..0f6338b 100644 (file)
@@ -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)>
 
index 4dd2572..344e8e1 100644 (file)
@@ -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++;
index 35fd887..c820bc5 100644 (file)
@@ -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
  *
  */
 
index d08bd9a..757c052 100644 (file)
@@ -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
  *
  */
 
index 2cd0fa3..cfec4db 100644 (file)
@@ -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
  *
  */
 
index ed260c6..048044b 100644 (file)
@@ -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
  *
  */
 
index 6ed690b..f7cecd2 100644 (file)
@@ -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";
index 2143cd9..6f25c58 100644 (file)
@@ -290,6 +290,14 @@ in their names.
 
 =item *
 
+L<Digest::SHA> has been upgraded from version 5.63 to version 5.70.
+
+Added BITS mode to addfile method and shasum which makes partial-byte inputs
+now possible via files/STDIN and allows shasum to check all 8074 NIST Msg vectors,
+where previously special programming was required to do this.
+
+=item *
+
 L<ExtUtils::ParseXS> has been upgraded from version 3.05 to version 3.07.
 
 =item *