Skip to content

Commit 1a8dc0e

Browse files
committed
Use Digest::SHA instead of Digest::SHA1
Switch from Digest::SHA1 to Digest::SHA, because: Digest::SHA is a bit faster than Digest::SHA1, Digest::SHA1 has been removed from some Linux distributions, Digest::SHA is a core library (as of Perl >= 5.10.0) and Digest::SHA1 is not (and never will be). See also: - https://src.fedoraproject.org/rpms/perl-Razor-Agent/c/75fa8a6c1f1fdf779312dac68f331a288bd2920f?branch=rawhide - https://stackoverflow.com/questions/3420720/what-are-the-advantages-of-digestsha-over-digestsha1 Original author: Warren Togami <[email protected]>
1 parent 6244ee8 commit 1a8dc0e

File tree

8 files changed

+24
-30
lines changed

8 files changed

+24
-30
lines changed

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ option, like so:
2525
following Perl modules from CPAN:
2626

2727
Time::HiRes
28-
Digest::SHA1
28+
Digest::SHA
2929
MIME::Base64
3030
Test::Simple
3131
Test::Harness

META.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"runtime" : {
3535
"requires" : {
36-
"Digest::SHA1" : "0",
36+
"Digest::SHA" : "0",
3737
"File::Copy" : "0",
3838
"File::Spec" : "0",
3939
"Getopt::Long" : "0",

META.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ no_index:
1919
- t
2020
- inc
2121
requires:
22-
Digest::SHA1: '0'
22+
Digest::SHA: '0'
2323
File::Copy: '0'
2424
File::Spec: '0'
2525
Getopt::Long: '0'

Makefile.PL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ WriteMakefile(
2222
( $ExtUtils::MakeMaker::VERSION >= 6.3002 ? ( 'LICENSE' => 'perl', ) : () ),
2323
EXE_FILES => [qw( bin/razor-client bin/razor-admin bin/razor-check bin/razor-report bin/razor-revoke )],
2424
PREREQ_PM => {
25-
'Digest::SHA1' => 0,
25+
'Digest::SHA' => 0,
2626
'File::Copy' => 0,
2727
'File::Spec' => 0,
2828
'Getopt::Long' => 0,

lib/Razor2/Client/Engine.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package Razor2::Client::Engine;
22

33
use strict;
4-
use Digest::SHA1 qw(sha1_hex);
54
use Data::Dumper;
65
use Razor2::Signature::Ephemeral;
76
use Razor2::Engine::VR8;

lib/Razor2/Signature/Ephemeral.pm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
package Razor2::Signature::Ephemeral;
44
use strict;
5-
use Digest::SHA1;
65
use Data::Dumper;
76

7+
BEGIN {
8+
eval { require Digest::SHA; import Digest::SHA qw(sha1_hex); 1 }
9+
or do { require Digest::SHA1; import Digest::SHA1 qw(sha1_hex) }
10+
}
11+
812
sub new {
913

1014
my ( $class, %args ) = @_;
@@ -88,17 +92,13 @@ sub hexdigest {
8892
}
8993

9094
my $digest;
91-
my $ctx = Digest::SHA1->new;
9295

9396
if ( $seclength > 128 ) {
94-
$ctx->add($section1);
95-
$ctx->add($section2);
96-
$digest = $ctx->hexdigest;
97+
$digest = sha1_hex($section1, $section2);
9798
}
9899
else {
99100
debug("Sections too small... reverting back to orginal content.");
100-
$ctx->add($content);
101-
$digest = $ctx->hexdigest;
101+
$digest = sha1_hex($content);
102102
}
103103

104104
debug("Computed e-hash is $digest");

lib/Razor2/Signature/Whiplash.pm

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
package Razor2::Signature::Whiplash;
99

10-
use Digest::SHA1;
10+
BEGIN {
11+
eval { require Digest::SHA; import Digest::SHA qw(sha1_hex); 1 }
12+
or do { require Digest::SHA1; import Digest::SHA1 qw(sha1_hex) }
13+
}
1114

1215
sub new {
1316

@@ -682,13 +685,8 @@ sub whiplash {
682685
# the value of length to the nearest multiple of ``length_error''.
683686
# Take the first 20 hex chars from SHA1 and call it the signature.
684687

685-
my $sha1 = Digest::SHA1->new();
686-
687-
$sha1->add($host);
688-
$sig = substr $sha1->hexdigest, 0, 12;
689-
690-
$sha1->add($corrected_length);
691-
$sig .= substr $sha1->hexdigest, 0, 4;
688+
$sig = substr sha1_hex($host), 0, 12;
689+
$sig .= substr sha1_hex($corrected_length), 0, 4;
692690

693691
push @sigs, $sig;
694692
$sig_meta{$sig} = [ $host, $corrected_length ];

lib/Razor2/String.pm

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# $Id: String.pm,v 1.48 2005/06/13 21:09:59 vipul Exp $
22
package Razor2::String;
33

4-
use Digest::SHA1 qw(sha1_hex);
54
use URI::Escape;
65
use Razor2::Preproc::enBase64;
76
use Data::Dumper;
87

8+
BEGIN {
9+
eval { require Digest::SHA; import Digest::SHA qw(sha1_hex); 1 }
10+
or do { require Digest::SHA1; import Digest::SHA1 qw(sha1_hex) }
11+
}
12+
913
#use MIME::Parser;
1014

1115
require Exporter;
@@ -65,15 +69,8 @@ sub hmac2_sha1 {
6569
return unless $text && $iv1 && $iv2;
6670
die "no ref's allowed" if ref($text);
6771

68-
my $ctx = Digest::SHA1->new;
69-
$ctx->add($iv2);
70-
$ctx->add($text);
71-
my $digest = $ctx->hexdigest;
72-
73-
$ctx = Digest::SHA1->new;
74-
$ctx->add($iv1);
75-
$ctx->add($digest);
76-
$digest = $ctx->hexdigest;
72+
my $digest = sha1_hex($iv2, $text);
73+
$digest = sha1_hex($iv1, $digest);
7774

7875
return ( hextobase64($digest), $digest );
7976
}

0 commit comments

Comments
 (0)