Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
HmacSha1 | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
buildSignature | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * @section LICENSE |
4 | * Copyright (c) 2007 Andy Smith |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining |
7 | * a copy of this software and associated documentation files (the |
8 | * "Software"), to deal in the Software without restriction, including without |
9 | * limitation the rights to use, copy, modify, merge, publish, distribute, |
10 | * sublicense, and/or sell copies of the Software, and to permit persons to |
11 | * whom the Software is furnished to do so, subject to the following |
12 | * conditions: |
13 | * |
14 | * The above copyright notice and this permission notice shall be included in |
15 | * all copies or substantial portions of the Software. |
16 | * |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
23 | * DEALINGS IN THE SOFTWARE. |
24 | * |
25 | * @file |
26 | */ |
27 | |
28 | namespace MediaWiki\OAuthClient\SignatureMethod; |
29 | |
30 | use MediaWiki\OAuthClient\Consumer; |
31 | use MediaWiki\OAuthClient\Request; |
32 | use MediaWiki\OAuthClient\SignatureMethod; |
33 | use MediaWiki\OAuthClient\Token; |
34 | use MediaWiki\OAuthClient\Util; |
35 | |
36 | /** |
37 | * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as |
38 | * defined in [RFC2104] where the Signature Base String is the text and the |
39 | * key is the concatenated values (each first encoded per Parameter Encoding) |
40 | * of the Consumer Secret and Token Secret, separated by an '&' character |
41 | * (ASCII code 38) even if empty. |
42 | * - Chapter 9.2 ("HMAC-SHA1") |
43 | */ |
44 | class HmacSha1 extends SignatureMethod { |
45 | |
46 | /** |
47 | * @return string |
48 | */ |
49 | public function getName() { |
50 | return 'HMAC-SHA1'; |
51 | } |
52 | |
53 | /** |
54 | * @param Request $request |
55 | * @param Consumer $consumer |
56 | * @param Token|null $token |
57 | * @return string |
58 | */ |
59 | public function buildSignature( |
60 | Request $request, |
61 | Consumer $consumer, |
62 | Token $token = null |
63 | ) { |
64 | $base_string = $request->getSignatureBaseString(); |
65 | |
66 | $key_parts = [ |
67 | $consumer->secret, |
68 | $token ? $token->secret : '' |
69 | ]; |
70 | |
71 | $key_parts = Util::urlencode( $key_parts ); |
72 | $key = implode( '&', $key_parts ); |
73 | |
74 | return base64_encode( hash_hmac( 'sha1', $base_string, $key, true ) ); |
75 | } |
76 | } |