diff options
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Digest/SHA.pm')
-rw-r--r-- | Master/tlpkg/tlperl/lib/Digest/SHA.pm | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/Master/tlpkg/tlperl/lib/Digest/SHA.pm b/Master/tlpkg/tlperl/lib/Digest/SHA.pm index f809ce3afbc..d8cc56136be 100644 --- a/Master/tlpkg/tlperl/lib/Digest/SHA.pm +++ b/Master/tlpkg/tlperl/lib/Digest/SHA.pm @@ -7,7 +7,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); use Fcntl; use integer; -$VERSION = '5.61'; +$VERSION = '5.71'; require Exporter; require DynaLoader; @@ -28,19 +28,16 @@ require DynaLoader; sha512224 sha512224_base64 sha512224_hex sha512256 sha512256_base64 sha512256_hex); -# If possible, inherit from Digest::base (which depends on MIME::Base64) - -*addfile = \&Addfile; +# If possible, inherit from Digest::base eval { - require MIME::Base64; require Digest::base; push(@ISA, 'Digest::base'); }; -if ($@) { - *hexdigest = \&Hexdigest; - *b64digest = \&B64digest; -} + +*addfile = \&Addfile; +*hexdigest = \&Hexdigest; +*b64digest = \&B64digest; # The following routines aren't time-critical, so they can be left in Perl @@ -84,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); } @@ -91,8 +89,9 @@ sub add_bits { sub _bail { my $msg = shift; + $msg .= ": $!"; require Carp; - Carp::croak("$msg: $!"); + Carp::croak($msg); } sub _addfile { # this is "addfile" from Digest::base 1.00 @@ -115,7 +114,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 @@ -123,8 +122,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); @@ -514,15 +524,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)> @@ -672,6 +687,7 @@ The author is particularly grateful to Chris Carey Alexandr Ciornii Jim Doble + Thomas Drugeon Julius Duque Jeffrey Friedl Robert Gilmour @@ -691,7 +707,7 @@ darkness and moored it in so perfect a calm and in so brilliant a light" =head1 COPYRIGHT AND LICENSE -Copyright (C) 2003-2011 Mark Shelor +Copyright (C) 2003-2012 Mark Shelor This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |