Lite/SignatureMethod.pm

filter: Statementstmt 87.5% 21 / 24 Branchbran 100% 2 / 2 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 77.7% 7 / 9 Podpod 100% 5 / 5 totaltotal 89.1% 41 / 46 SCAR 13.9
CC
4
Cov
90%
new
3.0
build_body_hash
2.0
sign
2.0
CRAP 4.0
« Lite/Agent.pm ↑ Summary Lite/Problems.pm »
1 package OAuth::Lite::SignatureMethod;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use base 'Class::Data::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 __PACKAGE__->mk_classaccessor('method_name');
9  
10 8 ▶use OAuth::Lite::Util qw(encode_param);
Subroutine BEGIN: called CC=1 SCAR=0.0
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 ▶ my ( $class, $content ) = @_;
Subroutine build_body_hash: not called CC=1 SCAR=6.9
Pod documented
51 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 ▶ my ($class, %args) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
73 my $self = bless {
74 consumer_secret => $args{consumer_secret} || '',
75 26 ▶ token_secret => $args{token_secret} || '',
Condition100%4/4
$args{'consumer_secret'} || ''
l!l
251
$args{'token_secret'} || ''
l!l
620
MC/DC100%1/1
$args{'consumer_secret'} || ''
$args{'consumer_secret'}
MC/DC100%1/1
$args{'token_secret'} || ''
$args{'token_secret'}
Truth table100%2/2
A
A= $args{'consumer_secret'}
Aresult
11
00
Truth table100%2/2
A
A= $args{'token_secret'}
Aresult
11
00
76 }, $class;
77 26 $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 ▶ my $self = shift;
Subroutine secrets_as_key: called CC=1 SCAR=0.0
Pod documented
90 27 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 ▶ my ($self, $base_string) = @_;
Subroutine sign: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my ($self, $base_string, $signature) = @_;
Subroutine verify: called CC=2 SCAR=6.9
Pod documented
122 10 ▶ return ($signature eq $self->sign($base_string)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$signature eq $self->sign($base_string) ? : 5 5 10
123 }
124  
125 =head1 SEE ALSO
126  
127 L<OAuth::Lite::SignatureMethod::HMAC_SHA1>
128 L<OAuth::Lite::SignatureMethod::PLAINTEXT>
129 L<OAuth::Lite::SignatureMethod::RSA_SHA1>
130  
131 =head1 AUTHOR
132  
133 Lyo Kato, C<lyo.kato _at_ gmail.com>
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 8 1;
« Lite/Agent.pm ↑ Summary Lite/Problems.pm »