Completed
Push — master ( 9473ea...cfd0e6 )
by Michał
05:47
created

HmacSha1   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSignatureMethod() 0 4 1
A sign() 0 4 1
A hash() 0 4 1
1
<?php namespace nyx\auth\id\protocols\oauth1\signers;
2
3
// External dependencies
4
use Psr\Http\Message\RequestInterface as Request;
5
6
// Internal dependencies
7
use nyx\auth\id\protocols\oauth1;
8
use nyx\auth;
9
10
/**
11
 * OAuth 1.0a HMAC-SHA1 Request Signer
12
 *
13
 * @package     Nyx\Auth
14
 * @version     0.1.0
15
 * @author      Michal Chojnacki <[email protected]>
16
 * @copyright   2012-2017 Nyx Dev Team
17
 * @link        https://github.com/unyx/nyx
18
 * ----
19
 * @see         https://oauth.net/core/1.0a/#anchor15 (Spec #9.2 HMAC-SHA1)
20
 */
21
class HmacSha1 extends oauth1\Signer
22
{
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function getSignatureMethod() : string
27
    {
28
        return oauth1\interfaces\Signer::METHOD_HMAC_SHA1;
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    public function sign(Request $request, array $params, auth\id\credentials\Client $client, auth\interfaces\Credentials $token = null) : string
35
    {
36
        return base64_encode($this->hash($this->buildBaseString($request, $params), $this->createKey($client, $token)));
37
    }
38
39
    /**
40
     * Hashes a string with the signature's key.
41
     *
42
     * @param   string  $string
43
     * @return  string
44
     */
45
    protected function hash(string $string, string $key) : string
46
    {
47
        return hash_hmac('sha1', $string, $key, true);
48
    }
49
}
50