PluginProbe
Media Cloud Sync / 1.2.3
Media Cloud Sync v1.2.3
1.4.2 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 All 36 releases
media-cloud-sync / includes / sdk / s3 / Aws / S3 / CalculatesChecksumTrait.php

CalculatesChecksumTrait.php in Media Cloud Sync 1.2.3, at includes/sdk/s3/Aws/S3/CalculatesChecksumTrait.php

44 lines 1.7 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\S3;
4
5 use Dudlewebs\WPMCS\s3\AWS\CRT\CRT;
6 use Dudlewebs\WPMCS\s3\Aws\Exception\CommonRuntimeException;
7 use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;
8 use InvalidArgumentException;
9 trait CalculatesChecksumTrait
10 {
11 /**
12 * @param string $requestedAlgorithm the algorithm to encode with
13 * @param string $value the value to be encoded
14 * @return string
15 */
16 public static function getEncodedValue($requestedAlgorithm, $value)
17 {
18 $requestedAlgorithm = \strtolower($requestedAlgorithm);
19 $useCrt = \extension_loaded('awscrt');
20 if ($useCrt) {
21 switch ($requestedAlgorithm) {
22 case 'crc32c':
23 return CRT::crc32c($value);
24 case 'crc32':
25 return CRT::crc32($value);
26 case 'sha256':
27 case 'sha1':
28 return \base64_encode(Psr7\Utils::hash($value, $requestedAlgorithm, \true));
29 default:
30 break;
31 throw new InvalidArgumentException("Invalid checksum requested: {$requestedAlgorithm}." . " Valid algorithms are CRC32C, CRC32, SHA256, and SHA1.");
32 }
33 } else {
34 if ($requestedAlgorithm == 'crc32c') {
35 throw new CommonRuntimeException("crc32c is not supported for checksums " . "without use of the common runtime for php. Please enable the CRT or choose " . "a different algorithm.");
36 }
37 if ($requestedAlgorithm == "crc32") {
38 $requestedAlgorithm = "crc32b";
39 }
40 return \base64_encode(Psr7\Utils::hash($value, $requestedAlgorithm, \true));
41 }
42 }
43 }
44