line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::WebToken::Crypt::HMAC; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
1758
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
125
|
|
4
|
4
|
|
|
4
|
|
14
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
91
|
|
5
|
4
|
|
|
4
|
|
13
|
use parent 'JSON::WebToken::Crypt'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
22
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
2130
|
use Digest::SHA (); |
|
4
|
|
|
|
|
11954
|
|
|
4
|
|
|
|
|
644
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $ALGORITHM2SIGNING_METHOD_MAP = { |
10
|
|
|
|
|
|
|
HS256 => \&Digest::SHA::hmac_sha256, |
11
|
|
|
|
|
|
|
HS384 => \&Digest::SHA::hmac_sha384, |
12
|
|
|
|
|
|
|
HS512 => \&Digest::SHA::hmac_sha512, |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub sign { |
16
|
20
|
|
|
20
|
0
|
27
|
my ($class, $algorithm, $message, $key) = @_; |
17
|
|
|
|
|
|
|
|
18
|
20
|
|
|
|
|
21
|
my $sign = ''; |
19
|
20
|
|
|
|
|
27
|
my $method = $ALGORITHM2SIGNING_METHOD_MAP->{$algorithm}; |
20
|
20
|
|
|
|
|
264
|
return $method->($message, $key); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub verify { |
24
|
9
|
|
|
9
|
0
|
16
|
my ($class, $algorithm, $message, $key, $signature) = @_; |
25
|
9
|
|
|
|
|
16
|
my $sign = $class->sign($algorithm, $message, $key); |
26
|
9
|
100
|
|
|
|
49
|
return $sign eq $signature ? 1 : 0; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
__END__ |