line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuth::Lite::SignatureMethod; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
55
|
use strict; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
345
|
|
4
|
8
|
|
|
8
|
|
45
|
use warnings; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
588
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
46
|
use base 'Class::Data::Accessor'; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
8388
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_classaccessor('method_name'); |
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
28177
|
use OAuth::Lite::Util qw(encode_param); |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
2432
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
OAuth::Lite::SignatureMethod - signature method base class |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
say $signature_method_class->method_name; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $method = $signature_method_class->new( |
21
|
|
|
|
|
|
|
consumer_secret => $consumer_secret, |
22
|
|
|
|
|
|
|
token_secret => $token_secret, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $signature = $method->sign($text); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if ($method->verify($text, $signature)) { |
28
|
|
|
|
|
|
|
say "valid signature"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
SignatureMethod base class. |
35
|
|
|
|
|
|
|
Create subclasses for arbitrary signature method inheriting this class. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 build_body_hash($content) |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Build body hash according to the spec |
42
|
|
|
|
|
|
|
http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/drafts/4/spec.html |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $hash = $method_class->build_body_hash($content); |
45
|
|
|
|
|
|
|
say $hash; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub build_body_hash { |
50
|
0
|
|
|
0
|
1
|
0
|
my ( $class, $content ) = @_; |
51
|
0
|
|
|
|
|
0
|
return; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 method_name($method_name) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Set signature method name. |
57
|
|
|
|
|
|
|
Use this in subclass. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$method_class->method_name('HMAC-SHA1'); |
60
|
|
|
|
|
|
|
say $method_class->method_name; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 new(%params) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $method = $signature_method_class->new( |
65
|
|
|
|
|
|
|
consumer_secret => $consumer_secret, |
66
|
|
|
|
|
|
|
token_secret => $token_secret, |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub new { |
72
|
26
|
|
|
26
|
1
|
4019
|
my ($class, %args) = @_; |
73
|
26
|
|
100
|
|
|
334
|
my $self = bless { |
|
|
|
100
|
|
|
|
|
74
|
|
|
|
|
|
|
consumer_secret => $args{consumer_secret} || '', |
75
|
|
|
|
|
|
|
token_secret => $args{token_secret} || '', |
76
|
|
|
|
|
|
|
}, $class; |
77
|
26
|
|
|
|
|
144
|
$self; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 secrets_as_key |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Returns consumer_secret and token_secret as encoded key format. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $key = $method->secrets_as_key; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub secrets_as_key { |
89
|
27
|
|
|
27
|
1
|
52
|
my $self = shift; |
90
|
27
|
|
|
|
|
178
|
join '&', (map encode_param($self->{$_}), |
91
|
|
|
|
|
|
|
qw/consumer_secret token_secret/); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 sign($base_text) |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Create signature from passed base text |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This is an abstract method. |
99
|
|
|
|
|
|
|
Define this in subclass. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $signature = $method->sign($base_text); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub sign { |
106
|
0
|
|
|
0
|
1
|
0
|
my ($self, $base_string) = @_; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 verify($base_text, $signature) |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Check if signature is valid with base text |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $signature_is_valid = $method->verify($base_text, $signature); |
114
|
|
|
|
|
|
|
if ($signature_is_valid) { |
115
|
|
|
|
|
|
|
... |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub verify { |
121
|
10
|
|
|
10
|
1
|
175
|
my ($self, $base_string, $signature) = @_; |
122
|
10
|
100
|
|
|
|
59
|
return ($signature eq $self->sign($base_string)) ? 1 : 0; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SEE ALSO |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L |
128
|
|
|
|
|
|
|
L |
129
|
|
|
|
|
|
|
L |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 AUTHOR |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Lyo Kato, C |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
138
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
139
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |