Subject: | [PATCH] Use Digest::SHA instead of Digest::SHA1 |
Digest::SHA is a superset of the functionality in Digest::SHA1.
Furthermore, it is now in core. I've attached a patch that replaces the
use of Digest::SHA1 with Digest::SHA. Additionally, it adds support for
the four SHA-2 algorithms, making Crypt::OpenPGP able to use all the
algorithms available in RFC 4880.
Subject: | digest-sha.patch |
diff --git a/lib/Crypt/OpenPGP/Digest.pm b/lib/Crypt/OpenPGP/Digest.pm
index 6b76cad..d52fcf6 100644
--- a/lib/Crypt/OpenPGP/Digest.pm
+++ b/lib/Crypt/OpenPGP/Digest.pm
@@ -9,6 +9,10 @@ use vars qw( %ALG %ALG_BY_NAME );
1 => 'MD5',
2 => 'SHA1',
3 => 'RIPEMD160',
+ 8 => 'SHA256',
+ 9 => 'SHA384',
+ 10 => 'SHA512',
+ 11 => 'SHA224',
);
%ALG_BY_NAME = map { $ALG{$_} => $_ } keys %ALG;
@@ -64,8 +68,8 @@ use base qw( Crypt::OpenPGP::Digest );
sub init {
my $dig = shift;
- require Digest::SHA1;
- $dig->{md} = \&Digest::SHA1::sha1;
+ require Digest::SHA;
+ $dig->{md} = \&Digest::SHA::sha1;
$dig;
}
@@ -80,6 +84,51 @@ sub init {
$dig;
}
+package Crypt::OpenPGP::Digest::SHA224;
+use strict;
+use base qw( Crypt::OpenPGP::Digest );
+
+sub init {
+ my $dig = shift;
+ require Digest::SHA;
+ $dig->{md} = \&Digest::SHA::sha224;
+ $dig;
+}
+
+package Crypt::OpenPGP::Digest::SHA256;
+use strict;
+use base qw( Crypt::OpenPGP::Digest );
+
+sub init {
+ my $dig = shift;
+ require Digest::SHA;
+ $dig->{md} = \&Digest::SHA::sha256;
+ $dig;
+}
+
+package Crypt::OpenPGP::Digest::SHA384;
+use strict;
+use base qw( Crypt::OpenPGP::Digest );
+
+sub init {
+ my $dig = shift;
+ require Digest::SHA;
+ $dig->{md} = \&Digest::SHA::sha384;
+ $dig;
+}
+
+package Crypt::OpenPGP::Digest::SHA512;
+use strict;
+use base qw( Crypt::OpenPGP::Digest );
+
+sub init {
+ my $dig = shift;
+ require Digest::SHA;
+ $dig->{md} = \&Digest::SHA::sha512;
+ $dig;
+}
+
+
1;
__END__
diff --git a/t/07-digest.t b/t/07-digest.t
index 725654f..c083ae3 100644
--- a/t/07-digest.t
+++ b/t/07-digest.t
@@ -8,6 +8,10 @@ my %TESTDATA = (
1 => [ 16, '6abb1d8ca3f00772440701359a8b2fcf' ],
2 => [ 20, '37316c7b5cd5c1953ba5d9752c4dabe959c8af53' ],
3 => [ 20, 'd3d53bea7a263f0086f6a1584c52dfae9e494ce8' ],
+ 8 => [ 32, 'ba8a15767957c344dd23e38f6d00115cf00a2dfb1b7f28c5a85c863abd951746' ],
+ 9 => [ 48, '0cee26e732f687308124849c6fd97f39acf5267d45246bd520fdae880e17c9c749ee4bc987642811eefb44e920c764b3' ],
+ 10 => [ 64, '1849c153b7aaca8eedd1e774191770c94f347ad65be3cb4733406c1d56b17512122bb7cbbdf3e6377aa4c5b3c72433c64f590d321671dc3aa7fc93fdeafebd68' ],
+ 11 => [ 28, '6576f1956f2ba82934ff3b540eb284168c371b9c66d4c6d7bc2a731a' ],
);
my $data = <<TEXT;
@@ -55,4 +59,4 @@ for my $did ( sort { $a <=> $b } keys %TESTS ) {
}
is $hash, pack( 'H*', $TESTDATA{$did}[1] ), 'digest data matches';
}
-}
\ No newline at end of file
+}