summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorSteve Peters <steve@fisharerojo.org>2006-07-27 21:17:10 +0000
committerSteve Peters <steve@fisharerojo.org>2006-07-27 21:17:10 +0000
commitcccd58310685ffd16595b2773caa8f1346d6b0ee (patch)
tree2d27d74e74dbf3173b671d6294b25a50a4c874e4 /ext
parent670f1322a800dc03404a696600a617f3804f797d (diff)
downloadperl-cccd58310685ffd16595b2773caa8f1346d6b0ee.tar.gz
Upgrade to Digest-SHA-5.42
p4raw-id: //depot/perl@28627
Diffstat (limited to 'ext')
-rw-r--r--ext/Digest/SHA/Changes9
-rw-r--r--ext/Digest/SHA/README2
-rw-r--r--ext/Digest/SHA/SHA.pm56
-rwxr-xr-xext/Digest/SHA/bin/shasum16
-rw-r--r--ext/Digest/SHA/src/hmac.c4
-rw-r--r--ext/Digest/SHA/src/hmac.h4
-rw-r--r--ext/Digest/SHA/src/sha.c4
-rw-r--r--ext/Digest/SHA/src/sha.h4
-rw-r--r--ext/Digest/SHA/t/1-exist.t1
-rw-r--r--ext/Digest/SHA/t/2-nist-sha-oo.t50
-rw-r--r--ext/Digest/SHA/t/2-nist-vectors-bit.t14
-rw-r--r--ext/Digest/SHA/t/2-nist-vectors-byte.t14
-rw-r--r--ext/Digest/SHA/t/3-gillogly-hard.t7
-rw-r--r--ext/Digest/SHA/t/6-dump-load.t8
-rw-r--r--ext/Digest/SHA/t/7-ireland.t5
15 files changed, 118 insertions, 80 deletions
diff --git a/ext/Digest/SHA/Changes b/ext/Digest/SHA/Changes
index 9b488b5b3d..a71c9cb0ed 100644
--- a/ext/Digest/SHA/Changes
+++ b/ext/Digest/SHA/Changes
@@ -1,5 +1,14 @@
Revision history for Perl extension Digest::SHA.
+5.42 Mon Jul 24 04:04:40 MST 2006
+ - minor code changes suggested by Perl::Critic
+ -- e.g. no bareword filehandles, no 2-argument open's
+ - updated public key (ref. B538C51C)
+ -- previous one (0AF563FE) expired July 2, 2006
+ - added documentation to warn that Base64 digests are NOT padded
+ -- padding must be done by user if interoperability
+ with other software is required
+
5.41 Sat Jun 3 01:50:46 MST 2006
- corrected addfile
-- process $file argument as a filehandle unless passed
diff --git a/ext/Digest/SHA/README b/ext/Digest/SHA/README
index 2121cbdda1..f4352c8d40 100644
--- a/ext/Digest/SHA/README
+++ b/ext/Digest/SHA/README
@@ -1,4 +1,4 @@
-Digest::SHA version 5.41
+Digest::SHA version 5.42
========================
Digest::SHA is a complete implementation of the NIST Secure Hash
diff --git a/ext/Digest/SHA/SHA.pm b/ext/Digest/SHA/SHA.pm
index dc7929a2b6..320838eae9 100644
--- a/ext/Digest/SHA/SHA.pm
+++ b/ext/Digest/SHA/SHA.pm
@@ -6,7 +6,7 @@ use strict;
use warnings;
use integer;
-our $VERSION = '5.41';
+our $VERSION = '5.42';
require Exporter;
our @ISA = qw(Exporter);
@@ -118,22 +118,21 @@ sub Addfile {
my ($binary, $portable) = map { $_ eq $mode } ("b", "p");
my $text = -T $file;
- local *F;
- _bail("Open failed") unless open(F, "<$file");
- binmode(F) if $binary || $portable;
+ open(my $fh, q{<}, $file) or _bail("Open failed");
+ binmode($fh) if $binary || $portable;
unless ($portable && $text) {
- $self->_addfile(*F);
- close(F);
+ $self->_addfile($fh);
+ close($fh);
return($self);
}
my ($n1, $n2);
my ($buf1, $buf2) = ("", "");
- while (($n1 = read(F, $buf1, 4096))) {
+ while (($n1 = read($fh, $buf1, 4096))) {
while (substr($buf1, -1) eq "\015") {
- $n2 = read(F, $buf2, 4096);
+ $n2 = read($fh, $buf2, 4096);
_bail("Read failed") unless defined $n2;
last unless $n2;
$buf1 .= $buf2;
@@ -143,7 +142,7 @@ sub Addfile {
$self->add($buf1);
}
_bail("Read failed") unless defined $n1;
- close(F);
+ close($fh);
$self;
}
@@ -323,6 +322,30 @@ the larger and stronger hash functions.>
ref. L<http://www.csrc.nist.gov/pki/HashWorkshop/NIST%20Statement/Burr_Mar2005.html>
+=head1 BASE64 DIGESTS
+
+By convention, CPAN Digest modules do not pad their Base64 output.
+This means that Base64 digests contain no trailing "=" characters.
+Unfortunately, problems can occur when feeding such digests to other
+software that expects properly padded Base64 encodings.
+
+For the time being, any necessary padding must be done by the user.
+Fortunately, the rule for accomplishing it is straightforward: if the
+length of a Base64-encoded digest isn't a multiple of 4, simply append
+1 or more "=" characters to the end of the digest until it is:
+
+ while (length($b64_digest) % 4) {
+ $b64_digest .= '=';
+ }
+
+To illustrate, I<sha256_base64("abc")> is computed to be
+
+ ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0
+
+which has a length of 43. So, the properly padded version is
+
+ ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=
+
=head1 EXPORT
None by default.
@@ -378,6 +401,11 @@ its SHA-1/224/256/384/512 digest encoded as a hexadecimal string.
Logically joins the arguments into a single string, and returns
its SHA-1/224/256/384/512 digest encoded as a Base64 string.
+It's important to note that the resulting string does B<not> contain
+the padding characters typical of Base64 encodings. This omission is
+deliberate, and is done to maintain compatibility with the family of
+CPAN Digest modules. See L</"BASE64 DIGESTS"> for details.
+
=back
I<OOP style>
@@ -527,6 +555,11 @@ the original digest state.
This method is inherited if L<Digest::base> is installed on your
system. Otherwise, a functionally equivalent substitute is used.
+It's important to note that the resulting string does B<not> contain
+the padding characters typical of Base64 encodings. This omission is
+deliberate, and is done to maintain compatibility with the family of
+CPAN Digest modules. See L</"BASE64 DIGESTS"> for details.
+
=back
I<HMAC-SHA-1/224/256/384/512>
@@ -578,6 +611,11 @@ with the result encoded as a Base64 string. Multiple I<$data>
arguments are allowed, provided that I<$key> is the last argument
in the list.
+It's important to note that the resulting string does B<not> contain
+the padding characters typical of Base64 encodings. This omission is
+deliberate, and is done to maintain compatibility with the family of
+CPAN Digest modules. See L</"BASE64 DIGESTS"> for details.
+
=back
=head1 SEE ALSO
diff --git a/ext/Digest/SHA/bin/shasum b/ext/Digest/SHA/bin/shasum
index 4899d6382d..1001ded7b5 100755
--- a/ext/Digest/SHA/bin/shasum
+++ b/ext/Digest/SHA/bin/shasum
@@ -4,8 +4,8 @@
#
# Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
#
- # Version: 5.41
- # Sat Jun 3 01:50:46 MST 2006
+ # Version: 5.42
+ # Mon Jul 24 04:04:40 MST 2006
=head1 NAME
@@ -22,7 +22,7 @@ shasum - Print or Check SHA Checksums
-b, --binary read files in binary mode (default on DOS/Windows)
-c, --check check SHA sums against given list
-p, --portable read files in portable mode
- produces same digest on Windows/Unix/MacOS 9
+ produces same digest on Windows/Unix/Mac
-t, --text read files in text mode (default)
The following two options are useful only when verifying checksums:
@@ -52,7 +52,7 @@ L<Digest::SHA::PurePerl>.
use strict;
use Getopt::Long;
-my $VERSION = "5.41";
+my $VERSION = "5.42";
# Try to use Digest::SHA, since it's faster. If not installed,
@@ -62,10 +62,10 @@ my $MOD_PREFER = "Digest::SHA";
my $MOD_SECOND = "Digest::SHA::PurePerl";
my $module = $MOD_PREFER;
-eval "require $module";
+eval "require $module"; ## no critic
if ($@) {
$module = $MOD_SECOND;
- eval "require $module";
+ eval "require $module"; ## no critic
die "Unable to find $MOD_PREFER or $MOD_SECOND\n" if $@;
}
@@ -92,7 +92,7 @@ With no FILE, or when FILE is -, read standard input.
-b, --binary read files in binary mode (default on DOS/Windows)
-c, --check check SHA sums against given list
-p, --portable read files in portable mode
- produces same digest on Windows/Unix/MacOS 9
+ produces same digest on Windows/Unix/Mac
-t, --text read files in text mode (default)
The following two options are useful only when verifying checksums:
@@ -201,7 +201,7 @@ if ($check) {
my ($fh, $sum, $fname, $rsp);
die "shasum: $checkfile: $!\n"
- unless open($fh, "<$checkfile");
+ unless open($fh, q{<}, $checkfile);
while (<$fh>) {
s/\s+$//;
($sum, $modesym, $fname) = /^(\S+) (.)(.*)$/;
diff --git a/ext/Digest/SHA/src/hmac.c b/ext/Digest/SHA/src/hmac.c
index a878cb595b..abb1bf5c35 100644
--- a/ext/Digest/SHA/src/hmac.c
+++ b/ext/Digest/SHA/src/hmac.c
@@ -5,8 +5,8 @@
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.41
- * Sat Jun 3 01:50:46 MST 2006
+ * Version: 5.42
+ * Mon Jul 24 04:04:40 MST 2006
*
*/
diff --git a/ext/Digest/SHA/src/hmac.h b/ext/Digest/SHA/src/hmac.h
index cf5ff7604b..28c5dd4d0d 100644
--- a/ext/Digest/SHA/src/hmac.h
+++ b/ext/Digest/SHA/src/hmac.h
@@ -5,8 +5,8 @@
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.41
- * Sat Jun 3 01:50:46 MST 2006
+ * Version: 5.42
+ * Mon Jul 24 04:04:40 MST 2006
*
*/
diff --git a/ext/Digest/SHA/src/sha.c b/ext/Digest/SHA/src/sha.c
index c057cb4127..12be3f8ead 100644
--- a/ext/Digest/SHA/src/sha.c
+++ b/ext/Digest/SHA/src/sha.c
@@ -5,8 +5,8 @@
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.41
- * Sat Jun 3 01:50:46 MST 2006
+ * Version: 5.42
+ * Mon Jul 24 04:04:40 MST 2006
*
*/
diff --git a/ext/Digest/SHA/src/sha.h b/ext/Digest/SHA/src/sha.h
index e9f038e998..122926afc7 100644
--- a/ext/Digest/SHA/src/sha.h
+++ b/ext/Digest/SHA/src/sha.h
@@ -5,8 +5,8 @@
*
* Copyright (C) 2003-2006 Mark Shelor, All Rights Reserved
*
- * Version: 5.41
- * Sat Jun 3 01:50:46 MST 2006
+ * Version: 5.42
+ * Mon Jul 24 04:04:40 MST 2006
*
*/
diff --git a/ext/Digest/SHA/t/1-exist.t b/ext/Digest/SHA/t/1-exist.t
index feaa355e1d..511fc690bf 100644
--- a/ext/Digest/SHA/t/1-exist.t
+++ b/ext/Digest/SHA/t/1-exist.t
@@ -1,4 +1,5 @@
use Test;
+use strict;
BEGIN {
if ($ENV{PERL_CORE}) {
diff --git a/ext/Digest/SHA/t/2-nist-sha-oo.t b/ext/Digest/SHA/t/2-nist-sha-oo.t
index a653a9986c..61c5e7c599 100644
--- a/ext/Digest/SHA/t/2-nist-sha-oo.t
+++ b/ext/Digest/SHA/t/2-nist-sha-oo.t
@@ -30,12 +30,11 @@ ok(Digest::SHA->new($NSA), undef);
# test OO methods using first two SHA-256 vectors from NIST
-my $temp = File::Spec->catfile(dirname($0), "oo.tmp");
-my $file = File::Spec->canonpath($temp);
-open(FILE, ">$file");
-binmode(FILE);
-print FILE "bcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
-close(FILE);
+my $file = File::Spec->catfile(dirname($0), "oo.tmp");
+open(my $fh, q{>}, $file);
+binmode($fh);
+print $fh "bcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
+close($fh);
my $ctx = Digest::SHA->new()->reset("SHA-256")->new();
$ctx->add_bits("a", 5)->add_bits("001");
@@ -44,14 +43,17 @@ my $rsp = shift(@vec);
ok($ctx->clone->add("b", "c")->b64digest, $rsp);
$rsp = shift(@vec);
-open(FILE, "<$file");
-binmode(FILE);
-ok($ctx->clone->addfile(*FILE)->hexdigest, $rsp);
-close(FILE);
- # use indirect filehandle
+ # test addfile with bareword filehandle
+
+open(FILE, "<$file"); ## no critic
+binmode(FILE); ## no critic
+ok($ctx->clone->addfile(*FILE)->hexdigest, $rsp); ## no critic
+close(FILE); ## no critic
-open(my $fh, "<$file");
+ # test addfile with indirect filehandle
+
+undef($fh); open($fh, q{<}, $file);
binmode($fh);
ok($ctx->clone->addfile($fh)->hexdigest, $rsp);
close($fh);
@@ -62,26 +64,26 @@ ok($ctx->addfile($file, "b")->hexdigest, $rsp);
# test addfile portable mode
-open(FILE, ">$file");
-binmode(FILE);
-print FILE "abc\012" x 2048; # using UNIX newline
-close(FILE);
+undef($fh); open($fh, q{>}, $file);
+binmode($fh);
+print $fh "abc\012" x 2048; # using UNIX newline
+close($fh);
ok($ctx->new(1)->addfile($file, "p")->hexdigest,
"d449e19c1b0b0c191294c8dc9fa2e4a6ff77fc51");
-open(FILE, ">$file");
-binmode(FILE);
-print FILE "abc\015\012" x 2048; # using DOS/Windows newline
-close(FILE);
+undef($fh); open($fh, q{>}, $file);
+binmode($fh);
+print $fh "abc\015\012" x 2048; # using DOS/Windows newline
+close($fh);
ok($ctx->new(1)->addfile($file, "p")->hexdigest,
"d449e19c1b0b0c191294c8dc9fa2e4a6ff77fc51");
-open(FILE, ">$file");
-binmode(FILE);
-print FILE "abc\015" x 2048; # using Apple/Mac newline
-close(FILE);
+undef($fh); open($fh, q{>}, $file);
+binmode($fh);
+print $fh "abc\015" x 2048; # using Apple/Mac newline
+close($fh);
ok($ctx->new(1)->addfile($file, "p")->hexdigest,
"d449e19c1b0b0c191294c8dc9fa2e4a6ff77fc51");
diff --git a/ext/Digest/SHA/t/2-nist-vectors-bit.t b/ext/Digest/SHA/t/2-nist-vectors-bit.t
index 0cd32eb0f1..e870836a30 100644
--- a/ext/Digest/SHA/t/2-nist-vectors-bit.t
+++ b/ext/Digest/SHA/t/2-nist-vectors-bit.t
@@ -23,9 +23,8 @@ my @hashes;
BEGIN {
my $file = File::Spec->catfile(dirname($0), "nist", "bit-hashes.sha1");
- my $datafile = File::Spec->canonpath($file);
- open(F, $datafile);
- while (<F>) {
+ open(my $fh, q{<}, $file);
+ while (<$fh>) {
next unless (/^[0-9A-F]/);
s/[\r\n]+$//;
if (/\^$/) {
@@ -33,7 +32,7 @@ BEGIN {
push(@hashes, $_);
}
}
- close(F);
+ close($fh);
plan tests => scalar(@hashes);
}
@@ -61,9 +60,8 @@ my $type3 = 0;
my $ctx = Digest::SHA->new(1);
my $file = File::Spec->catfile(dirname($0), "nist", "bit-messages.sha1");
-my $datafile = File::Spec->canonpath($file);
-open(F, $datafile);
-while (<F>) {
+open(my $fh, q{<}, $file);
+while (<$fh>) {
$type3 = 1 if (/Type 3/);
$type3 = 0 if (/^<D/);
next unless (/^[0-9^ ]/);
@@ -86,4 +84,4 @@ while (<F>) {
$line = "";
}
}
-close(F);
+close($fh);
diff --git a/ext/Digest/SHA/t/2-nist-vectors-byte.t b/ext/Digest/SHA/t/2-nist-vectors-byte.t
index 32dfb7c858..3a0d0b4f5a 100644
--- a/ext/Digest/SHA/t/2-nist-vectors-byte.t
+++ b/ext/Digest/SHA/t/2-nist-vectors-byte.t
@@ -23,9 +23,8 @@ my @hashes;
BEGIN {
my $file = File::Spec->catfile(dirname($0), "nist", "byte-hashes.sha1");
- my $datafile = File::Spec->canonpath($file);
- open(F, $datafile);
- while (<F>) {
+ open(my $fh, q{<}, $file);
+ while (<$fh>) {
next unless (/^[0-9A-F]/);
s/[\r\n]+$//;
if (/\^$/) {
@@ -33,7 +32,7 @@ BEGIN {
push(@hashes, $_);
}
}
- close(F);
+ close($fh);
plan tests => scalar(@hashes);
}
@@ -61,9 +60,8 @@ my $type3 = 0;
my $ctx = Digest::SHA->new(1);
my $file = File::Spec->catfile(dirname($0), "nist", "byte-messages.sha1");
-my $datafile = File::Spec->canonpath($file);
-open(F, $datafile);
-while (<F>) {
+open(my $fh, q{<}, $file);
+while (<$fh>) {
$type3 = 1 if (/Type 3/);
$type3 = 0 if (/^<D/);
next unless (/^[0-9^ ]/);
@@ -86,4 +84,4 @@ while (<F>) {
$line = "";
}
}
-close(F);
+close($fh);
diff --git a/ext/Digest/SHA/t/3-gillogly-hard.t b/ext/Digest/SHA/t/3-gillogly-hard.t
index a8169aad44..813d92aae2 100644
--- a/ext/Digest/SHA/t/3-gillogly-hard.t
+++ b/ext/Digest/SHA/t/3-gillogly-hard.t
@@ -54,11 +54,8 @@ BEGIN {
plan tests => scalar(@vec110) / 2 + scalar(@vec011) / 2;
}
-my $fileSTATE110 = File::Spec->catfile(dirname($0), "gillogly", "state.110");
-my $fileSTATE011 = File::Spec->catfile(dirname($0), "gillogly", "state.011");
-
-my $STATE110 = File::Spec->canonpath($fileSTATE110);
-my $STATE011 = File::Spec->canonpath($fileSTATE011);
+my $STATE110 = File::Spec->catfile(dirname($0), "gillogly", "state.110");
+my $STATE011 = File::Spec->catfile(dirname($0), "gillogly", "state.011");
my $reps = 1 << 14;
my $loops = int(1431655764 / $reps);
diff --git a/ext/Digest/SHA/t/6-dump-load.t b/ext/Digest/SHA/t/6-dump-load.t
index 27336bd9b3..874812c1f9 100644
--- a/ext/Digest/SHA/t/6-dump-load.t
+++ b/ext/Digest/SHA/t/6-dump-load.t
@@ -27,8 +27,7 @@ BEGIN {
my @ext = (1, 256, 384, 512);
my $data = "a" x 990000;
my $skip;
-my $tmpname = File::Spec->catfile(dirname($0), "dumpload.tmp");
-my $tmpfile = File::Spec->canonpath($tmpname);
+my $tmpfile = File::Spec->catfile(dirname($0), "dumpload.tmp");
for (my $i = 0; $i < @sharsp; $i++) {
$skip = 0;
@@ -41,11 +40,8 @@ for (my $i = 0; $i < @sharsp; $i++) {
my $digest;
unless ($skip) {
my $state;
- my $file;
- my $filename;
- $filename = File::Spec->catfile(dirname($0),
+ my $file = File::Spec->catfile(dirname($0),
"state", "state.$ext[$i]");
- $file = File::Spec->canonpath($filename);
unless ($state = Digest::SHA->load($file)) {
$state = Digest::SHA->new($ext[$i]);
$state->add($data);
diff --git a/ext/Digest/SHA/t/7-ireland.t b/ext/Digest/SHA/t/7-ireland.t
index 2deb097a70..86e7d989d4 100644
--- a/ext/Digest/SHA/t/7-ireland.t
+++ b/ext/Digest/SHA/t/7-ireland.t
@@ -18,9 +18,8 @@ BEGIN {
BEGIN { plan tests => 1 }
-my $filename = File::Spec->catfile(dirname($0), "ireland.tmp");
-my $file = File::Spec->canonpath($filename);
-open(F, ">$file"); while (<DATA>) { print F $_ } close(F);
+my $file = File::Spec->catfile(dirname($0), "ireland.tmp");
+open(my $fh, q{>}, $file); while (<DATA>) { print $fh $_ } close($fh);
my $data = "a" x 1000000;
my $vec = "b9045a713caed5dff3d3b783e98d1ce5778d8bc331ee4119d707072312af06a7";