diff options
author | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2011-12-14 12:09:12 +0000 |
---|---|---|
committer | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2011-12-14 12:09:12 +0000 |
commit | e39652eac43f367c8dc80418cc0c858496c83f83 (patch) | |
tree | d706a009e77d10c7747d6d4843001ad4dcaa52f1 /cpan/Digest-SHA/lib | |
parent | e46b6a3298faa41ef29068aa0bdd9f93fe720887 (diff) | |
download | perl-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/Digest-SHA/lib')
-rw-r--r-- | cpan/Digest-SHA/lib/Digest/SHA.pm | 39 |
1 files changed, 28 insertions, 11 deletions
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)> |