Completed
Pull Request — master (#3)
by Romain
01:42
created

XHubSignatureHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 1
A compute() 0 4 1
1
<?php
2
namespace Kerox\Messenger\Helper;
3
4
class XHubSignatureHelper
5
{
6
7
    /**
8
     * @param string $content
9
     * @param string $secret
10
     * @param string $signature
11
     * @return bool
12
     */
13
    public static function validate(string $content, string $secret, string $signature): bool
14
    {
15
        list($algorithm, $hash) = explode('=', $signature);
16
17
        return hash_equals(self::compute($algorithm, $content, $secret), $hash);
18
    }
19
20
    /**
21
     * @param string $algorithm
22
     * @param string $content
23
     * @param string $secret
24
     * @return string
25
     */
26
    private function compute(string $algorithm, string $content, string $secret): string
27
    {
28
        return hash_hmac($algorithm, $content, $secret);
29
    }
30
}
31