Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/S3/Crypto/CryptoParamsTrait.php

raw symbols SCIP
1 <?php
2 namespace Aws\S3\Crypto;
3
4 use Aws\Crypto\MaterialsProvider;
5 use Aws\Crypto\MetadataEnvelope;
6 use Aws\Crypto\MetadataStrategyInterface;
7
8 trait CryptoParamsTrait
9 {
10 protected function getMaterialsProvider(array $args)
11 {
12 if ($args['@MaterialsProvider'] instanceof MaterialsProvider) {
13 return $args['@MaterialsProvider'];
14 }
15
16 throw new \InvalidArgumentException('An instance of MaterialsProvider'
17 . ' must be passed in the "MaterialsProvider" field.');
18 }
19
20 protected function getInstructionFileSuffix(array $args)
21 {
22 //= ../specification/s3-encryption/data-format/metadata-strategy.md#instruction-file
23 //# Instruction File writes MUST be optionally configured during client creation or on each PutObject request.
24 return !empty($args['@InstructionFileSuffix'])
25 ? $args['@InstructionFileSuffix']
26 : $this->instructionFileSuffix;
27 }
28
29 protected function determineGetObjectStrategy(
30 $result,
31 $instructionFileSuffix
32 ) {
33 if (isset($result['Metadata'][MetadataEnvelope::CONTENT_KEY_V2_HEADER]) ||
34 isset($result['Metadata'][MetadataEnvelope::ENCRYPTED_DATA_KEY_V3])
35 ) {
36 return new HeadersMetadataStrategy();
37 }
38
39 return new InstructionFileMetadataStrategy(
40 $this->client,
41 $instructionFileSuffix
42 );
43 }
44
45 protected function getMetadataStrategy(array $args, $instructionFileSuffix)
46 {
47 if (!empty($args['@MetadataStrategy'])) {
48 if ($args['@MetadataStrategy'] instanceof MetadataStrategyInterface) {
49 return $args['@MetadataStrategy'];
50 }
51
52 if (is_string($args['@MetadataStrategy'])) {
53 switch ($args['@MetadataStrategy']) {
54 case HeadersMetadataStrategy::class:
55 return new HeadersMetadataStrategy();
56 case InstructionFileMetadataStrategy::class:
57 return new InstructionFileMetadataStrategy(
58 $this->client,
59 $instructionFileSuffix
60 );
61 default:
62 throw new \InvalidArgumentException('Could not match the'
63 . ' specified string in "MetadataStrategy" to a'
64 . ' predefined strategy.');
65 }
66 } else {
67 throw new \InvalidArgumentException('The metadata strategy that'
68 . ' was passed to "MetadataStrategy" was unrecognized.');
69 }
70 } elseif ($instructionFileSuffix) {
71 return new InstructionFileMetadataStrategy(
72 $this->client,
73 $instructionFileSuffix
74 );
75 }
76
77 return null;
78 }
79 }