line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::WebToken::Crypt::HMAC; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
2785
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
129
|
|
4
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
106
|
|
5
|
4
|
|
|
4
|
|
19
|
use parent 'JSON::WebToken::Crypt'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
31
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
4511
|
use Digest::SHA (); |
|
4
|
|
|
|
|
18500
|
|
|
4
|
|
|
|
|
685
|
|
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
|
41
|
my ($class, $algorithm, $message, $key) = @_; |
17
|
|
|
|
|
|
|
|
18
|
20
|
|
|
|
|
100
|
my $sign = ''; |
19
|
20
|
|
|
|
|
36
|
my $method = $ALGORITHM2SIGNING_METHOD_MAP->{$algorithm}; |
20
|
20
|
|
|
|
|
344
|
return $method->($message, $key); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub verify { |
24
|
9
|
|
|
9
|
0
|
21
|
my ($class, $algorithm, $message, $key, $signature) = @_; |
25
|
9
|
|
|
|
|
29
|
my $sign = $class->sign($algorithm, $message, $key); |
26
|
9
|
100
|
|
|
|
54
|
return $sign eq $signature ? 1 : 0; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
__END__ |