DerivedKey   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 53
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getNetworkKey() 0 4 1
A getSalt() 0 4 1
A generate() 0 5 1
1
<?php
2
3
namespace Acquia\Search;
4
5
/**
6
 * Generates a the derived key, which is the shared secret used to generate the
7
 * HMAC hash used to sign Acquia Search requests.
8
 */
9
class DerivedKey
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $salt;
15
16
    /**
17
     * @var string
18
     */
19
    protected $networkKey;
20
21
    /**
22
     * @param string $salt
23
     *   The derived key salt, or the shared secret used to generate the key.
24
     * @param string $networkKey
25
     *   The Acquia Network key of the subscription the index is associated
26
     *   with.
27
     */
28 9
    public function __construct($salt, $networkKey)
29
    {
30 9
        $this->salt = $salt;
31 9
        $this->networkKey = $networkKey;
32 9
    }
33
34
    /**
35
     * @return string
36
     */
37 3
    public function getNetworkKey()
38
    {
39 3
        return $this->networkKey;
40
    }
41
42
    /**
43
     * @return string
44
     */
45 3
    public function getSalt()
46
    {
47 3
        return $this->salt;
48
    }
49
50
    /**
51
     * @param string $indexId
52
     *   The unique identifier of the index, e.g. ABCD-12345.
53
     *
54
     * @return string
55
     */
56 6
    public function generate($indexId)
57
    {
58 6
        $string = $indexId . 'solr' . $this->salt;
59 6
        return hash_hmac('sha1', str_pad($string, 80, $string), $this->networkKey);
60
    }
61
}
62