line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
126053
|
use strict; use warnings; |
|
2
|
|
|
2
|
|
11
|
|
|
2
|
|
|
|
|
45
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
93
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package URI::Signature::Tiny; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.004'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
944
|
use Digest::SHA (); |
|
2
|
|
|
|
|
5109
|
|
|
2
|
|
|
|
|
50
|
|
8
|
2
|
|
|
2
|
|
11
|
use Carp (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
25
|
|
9
|
2
|
|
|
2
|
|
7
|
use Scalar::Util (); |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
954
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my @defaults = ( |
12
|
|
|
|
|
|
|
sort_params => 1, |
13
|
|
|
|
|
|
|
recode_base64 => 1, |
14
|
|
|
|
|
|
|
after_sign => sub { Carp::croak( 'No after_sign callback specified' ) }, |
15
|
|
|
|
|
|
|
before_verify => sub { Carp::croak( 'No before_verify callback specified' ) }, |
16
|
|
|
|
|
|
|
function => \&Digest::SHA::hmac_sha256_base64, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
26
|
|
|
26
|
1
|
3670
|
my $class = shift; |
21
|
26
|
|
|
|
|
107
|
my $self = bless { @defaults, @_ }, $class; |
22
|
26
|
100
|
|
|
|
265
|
Carp::croak( "Missing secret for $class" ) unless defined $self->{'secret'}; |
23
|
25
|
|
|
|
|
76
|
$self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub signature { |
27
|
23
|
|
|
23
|
1
|
7390
|
my ( $self, $uri ) = ( shift, @_ ); |
28
|
|
|
|
|
|
|
|
29
|
23
|
100
|
|
|
|
188
|
Carp::croak( 'Cannot compute the signature of an undefined value' ) unless defined $uri; |
30
|
|
|
|
|
|
|
|
31
|
21
|
100
|
|
|
|
90
|
$uri = $uri->isa( 'URI::WithBase' ) ? $uri->abs->as_string : $uri->as_string |
|
|
100
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if Scalar::Util::blessed( $uri ); |
33
|
|
|
|
|
|
|
|
34
|
21
|
100
|
|
|
|
595
|
$uri =~ m[ \A [^?#]* \? ]xgc and $uri =~ s[ \G ([^#]+) ]{ |
35
|
9
|
|
|
|
|
35
|
my @qp = split /[&;]/, "$1"; |
36
|
9
|
100
|
|
|
|
43
|
join ';', $self->{'sort_params'} ? sort @qp : @qp; |
37
|
|
|
|
|
|
|
}xe; |
38
|
|
|
|
|
|
|
|
39
|
21
|
|
|
|
|
175
|
my $sig = $self->{'function'}->( $uri, $self->{'secret'} ); |
40
|
|
|
|
|
|
|
|
41
|
21
|
100
|
66
|
|
|
104
|
$sig =~ s/=+\z//, $sig =~ y{+/}{-_} if defined $sig and $self->{'recode_base64'}; |
42
|
|
|
|
|
|
|
|
43
|
21
|
|
|
|
|
89
|
$sig; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub sign { |
47
|
3
|
|
|
3
|
1
|
6515
|
my ( $self, $uri ) = ( shift, @_ ); |
48
|
3
|
|
|
|
|
6
|
$self->{'after_sign'}->( $uri, $self->signature( $uri ) ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub verify { |
52
|
4
|
|
|
4
|
1
|
185
|
my $self = shift; |
53
|
4
|
|
|
|
|
14
|
my ( $uri, $sig ) = $self->{'before_verify'}->( @_ ); |
54
|
3
|
100
|
|
|
|
157
|
if ( defined $sig ) { |
55
|
2
|
|
|
|
|
12
|
my $computed = $self->signature( $uri ); |
56
|
2
|
50
|
|
|
|
30
|
defined $computed and $computed eq $sig; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |