line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::WebToken::Crypt::HMAC; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
1906
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
139
|
|
4
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
100
|
|
5
|
4
|
|
|
4
|
|
16
|
use parent 'JSON::WebToken::Crypt'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
25
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
15640
|
use Digest::SHA (); |
|
4
|
|
|
|
|
62327
|
|
|
4
|
|
|
|
|
594
|
|
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
|
23
|
|
|
23
|
0
|
34
|
my ($class, $algorithm, $message, $key) = @_; |
17
|
|
|
|
|
|
|
|
18
|
23
|
|
|
|
|
24
|
my $sign = ''; |
19
|
23
|
|
|
|
|
35
|
my $method = $ALGORITHM2SIGNING_METHOD_MAP->{$algorithm}; |
20
|
23
|
|
|
|
|
341
|
return $method->($message, $key); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub verify { |
24
|
11
|
|
|
11
|
0
|
17
|
my ($class, $algorithm, $message, $key, $signature) = @_; |
25
|
11
|
|
|
|
|
23
|
my $sign = $class->sign($algorithm, $message, $key); |
26
|
11
|
100
|
|
|
|
50
|
return $sign eq $signature ? 1 : 0; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
__END__ |