PluginProbe
Media Cloud Sync / 1.2.13
Media Cloud Sync v1.2.13
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Signature / SignatureTrait.php

SignatureTrait.php in Media Cloud Sync 1.2.13, at includes/sdk/s3/Aws/Signature/SignatureTrait.php

35 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Signature;
4
5 /**
6 * Provides signature calculation for SignatureV4.
7 */
8 trait SignatureTrait
9 {
10 /** @var array Cache of previously signed values */
11 private $cache = [];
12 /** @var int Size of the hash cache */
13 private $cacheSize = 0;
14 private function createScope($shortDate, $region, $service)
15 {
16 return "{$shortDate}/{$region}/{$service}/aws4_request";
17 }
18 private function getSigningKey($shortDate, $region, $service, $secretKey)
19 {
20 $k = $shortDate . '_' . $region . '_' . $service . '_' . $secretKey;
21 if (!isset($this->cache[$k])) {
22 // Clear the cache when it reaches 50 entries
23 if (++$this->cacheSize > 50) {
24 $this->cache = [];
25 $this->cacheSize = 0;
26 }
27 $dateKey = \hash_hmac('sha256', $shortDate, "AWS4{$secretKey}", \true);
28 $regionKey = \hash_hmac('sha256', $region, $dateKey, \true);
29 $serviceKey = \hash_hmac('sha256', $service, $regionKey, \true);
30 $this->cache[$k] = \hash_hmac('sha256', 'aws4_request', $serviceKey, \true);
31 }
32 return $this->cache[$k];
33 }
34 }
35