Completed
Push — master ( f7e09f...fa72d2 )
by Michał
01:58
created

RsaSha1::getGenerator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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 RSA-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/#anchor18 (Spec #9.3 RSA-SHA1)
20
 */
21 View Code Duplication
class RsaSha1 extends oauth1\Signer
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function getMethod() : string
27
    {
28
        return oauth1\interfaces\Signer::METHOD_RSA_SHA1;
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     *
34
     * Note: The OAUth Token is entirely ignored in this signing flow, as per spec.
35
     */
36
    public function sign(Request $request, array $params, auth\id\credentials\Client $client, auth\interfaces\Credentials $token = null) : string
37
    {
38
        // Base64 encode the generated base string signed using the RSA-SHA1 method using our client secret,
39
        // eg. its private key.
40
        return base64_encode($this->getGenerator()->sign($this->buildBaseString($request, $params), $client));
41
    }
42
43
    /**
44
     * Returns the base signature generator used by this Request Signer.
45
     *
46
     * @return  auth\interfaces\Signer
47
     */
48
    protected function getGenerator() : auth\interfaces\Signer
49
    {
50
        static $generator;
51
52
        return $generator ?? $generator = new auth\signers\rsa\Sha1;
53
    }
54
}
55