updated backend

This commit is contained in:
Torsten 2020-01-17 10:58:01 +01:00
parent 1fea0f4fe7
commit 11521c2339
3459 changed files with 72735 additions and 168535 deletions

View file

@ -25,7 +25,7 @@ class UriSigner
* @param string $secret A secret
* @param string $parameter Query string parameter to use
*/
public function __construct($secret, $parameter = '_hash')
public function __construct(string $secret, string $parameter = '_hash')
{
$this->secret = $secret;
$this->parameter = $parameter;
@ -47,12 +47,13 @@ class UriSigner
if (isset($url['query'])) {
parse_str($url['query'], $params);
} else {
$params = array();
$params = [];
}
$uri = $this->buildUrl($url, $params);
$params[$this->parameter] = $this->computeHash($uri);
return $uri.(false === strpos($uri, '?') ? '?' : '&').$this->parameter.'='.$this->computeHash($uri);
return $this->buildUrl($url, $params);
}
/**
@ -68,25 +69,25 @@ class UriSigner
if (isset($url['query'])) {
parse_str($url['query'], $params);
} else {
$params = array();
$params = [];
}
if (empty($params[$this->parameter])) {
return false;
}
$hash = urlencode($params[$this->parameter]);
$hash = $params[$this->parameter];
unset($params[$this->parameter]);
return $this->computeHash($this->buildUrl($url, $params)) === $hash;
return hash_equals($this->computeHash($this->buildUrl($url, $params)), $hash);
}
private function computeHash($uri)
private function computeHash(string $uri): string
{
return urlencode(base64_encode(hash_hmac('sha256', $uri, $this->secret, true)));
return base64_encode(hash_hmac('sha256', $uri, $this->secret, true));
}
private function buildUrl(array $url, array $params = array())
private function buildUrl(array $url, array $params = []): string
{
ksort($params, SORT_STRING);
$url['query'] = http_build_query($params, '', '&');