From ba43df375441eea77c4aa789a6fdcf47240c78c1 Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Mon, 26 Oct 2020 11:12:39 +0100 Subject: [PATCH] calculate sig a little bit differently --- composer.json | 1 + src/SignUrl.php | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 9f3d67b..689ca8f 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ }, "require": { "php": "~7.0", + "ext-json": "*", "guzzlehttp/psr7": "^1.7" } } diff --git a/src/SignUrl.php b/src/SignUrl.php index 33db492..9f947c1 100644 --- a/src/SignUrl.php +++ b/src/SignUrl.php @@ -40,8 +40,6 @@ public static function signUrl($url, $signKey, $until = null, $roundDateUpTo = 3 /** * Signs a rokka URL with a sign key and optional signature options. * - * @since 1.12.0 - * * @param string|UriInterface $url * @param string $signKey * @param array|null $options @@ -66,29 +64,29 @@ public static function signUrlWithOptions($url, $signKey, $options = null) } } - $signature = self::getSignature($url, $sigOptsBase64, $signKey); if (null !== $sigOptsBase64) { - // append sigopts to return url + // append sigopts to url $url = Uri::withQueryValue($url, 'sigopts', urlencode($sigOptsBase64)); } else { // else remove, if exists $url = Uri::withoutQueryValue($url, 'sigopts'); } + $signature = self::getSignature($url, $signKey); return Uri::withQueryValue($url, 'sig', $signature); } /** + * Gets signature for an Uri + * * @param \Psr\Http\Message\UriInterface $url - * @param string|null $optionsBase64 * @param string $signKey * * @return string */ - public static function getSignature(UriInterface $url, string $optionsBase64 = null, string $signKey): string + public static function getSignature(UriInterface $url, string $signKey): string { - // remove sig and sigopts, if they exist + // remove sig if it exists $url = Uri::withoutQueryValue($url, 'sig'); - $url = Uri::withoutQueryValue($url, 'sigopts'); $query = $url->getQuery(); $urlPath = $url->getPath() . ($query ? '?'.$query : ''); @@ -97,7 +95,7 @@ public static function getSignature(UriInterface $url, string $optionsBase64 = n $urlPath = '/'.$urlPath; } - $sigString = $urlPath . ':' . ($optionsBase64 ?? '') . ':' . $signKey; + $sigString = $urlPath . ':' . $signKey; return self::calculateSignature($sigString); }