PluginProbe
Media Cloud Sync / 1.2.2
Media Cloud Sync v1.2.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 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Api / Parser / Crc32ValidatingParser.php

Crc32ValidatingParser.php in Media Cloud Sync 1.2.2, at includes/sdk/s3/Aws/Api/Parser/Crc32ValidatingParser.php

39 lines 1.4 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\Api\Parser;
4
5 use Dudlewebs\WPMCS\s3\Aws\Api\StructureShape;
6 use Dudlewebs\WPMCS\s3\Aws\CommandInterface;
7 use Dudlewebs\WPMCS\s3\Aws\Exception\AwsException;
8 use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
9 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
10 use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;
11 /**
12 * @internal Decorates a parser and validates the x-amz-crc32 header.
13 */
14 class Crc32ValidatingParser extends AbstractParser
15 {
16 /**
17 * @param callable $parser Parser to wrap.
18 */
19 public function __construct(callable $parser)
20 {
21 $this->parser = $parser;
22 }
23 public function __invoke(CommandInterface $command, ResponseInterface $response)
24 {
25 if ($expected = $response->getHeaderLine('x-amz-crc32')) {
26 $hash = \hexdec(Psr7\Utils::hash($response->getBody(), 'crc32b'));
27 if ($expected != $hash) {
28 throw new AwsException("crc32 mismatch. Expected {$expected}, found {$hash}.", $command, ['code' => 'ClientChecksumMismatch', 'connection_error' => \true, 'response' => $response]);
29 }
30 }
31 $fn = $this->parser;
32 return $fn($command, $response);
33 }
34 public function parseMemberFromStream(StreamInterface $stream, StructureShape $member, $response)
35 {
36 return $this->parser->parseMemberFromStream($stream, $member, $response);
37 }
38 }
39