HmacSha1   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A buildSignature() 0 11 2
1
<?php
2
/**
3
 * The MIT License
4
 * Copyright (c) 2007 Andy Smith
5
 */
6
namespace Abraham\TwitterOAuth;
7
8
/**
9
 * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
10
 * where the Signature Base String is the text and the key is the concatenated values (each first
11
 * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
12
 * character (ASCII code 38) even if empty.
13
 *   - Chapter 9.2 ("HMAC-SHA1")
14
 */
15
class HmacSha1 extends SignatureMethod
16
{
17
    /**
18
     * {@inheritDoc}
19
     */
20
    public function getName()
21
    {
22
        return "HMAC-SHA1";
23
    }
24
25
    /**
26
     * {@inheritDoc}
27
     */
28
    public function buildSignature(Request $request, Consumer $consumer, Token $token = null)
29
    {
30
        $signatureBase = $request->getSignatureBaseString();
31
32
        $parts = [$consumer->secret, null !== $token ? $token->secret : ""];
33
34
        $parts = Util::urlencodeRfc3986($parts);
35
        $key = implode('&', $parts);
36
37
        return base64_encode(hash_hmac('sha1', $signatureBase, $key, true));
38
    }
39
}
40