HmacSha1::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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