| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\Crypto; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Aws\HasDataTrait; |
| 6 |
use ArrayAccess; |
| 7 |
use IteratorAggregate; |
| 8 |
use InvalidArgumentException; |
| 9 |
use JsonSerializable; |
| 10 |
/** |
| 11 |
* Stores encryption metadata for reading and writing. |
| 12 |
* |
| 13 |
* @internal |
| 14 |
*/ |
| 15 |
class MetadataEnvelope implements ArrayAccess, IteratorAggregate, JsonSerializable |
| 16 |
{ |
| 17 |
use HasDataTrait; |
| 18 |
const CONTENT_KEY_V2_HEADER = 'x-amz-key-v2'; |
| 19 |
const IV_HEADER = 'x-amz-iv'; |
| 20 |
const MATERIALS_DESCRIPTION_HEADER = 'x-amz-matdesc'; |
| 21 |
const KEY_WRAP_ALGORITHM_HEADER = 'x-amz-wrap-alg'; |
| 22 |
const CONTENT_CRYPTO_SCHEME_HEADER = 'x-amz-cek-alg'; |
| 23 |
const CRYPTO_TAG_LENGTH_HEADER = 'x-amz-tag-len'; |
| 24 |
const UNENCRYPTED_CONTENT_LENGTH_HEADER = 'x-amz-unencrypted-content-length'; |
| 25 |
private static $constants = []; |
| 26 |
public static function getConstantValues() |
| 27 |
{ |
| 28 |
if (empty(self::$constants)) { |
| 29 |
$reflection = new \ReflectionClass(static::class); |
| 30 |
foreach (\array_values($reflection->getConstants()) as $constant) { |
| 31 |
self::$constants[$constant] = \true; |
| 32 |
} |
| 33 |
} |
| 34 |
return \array_keys(self::$constants); |
| 35 |
} |
| 36 |
/** |
| 37 |
* @return void |
| 38 |
*/ |
| 39 |
#[\ReturnTypeWillChange] |
| 40 |
public function offsetSet($name, $value) |
| 41 |
{ |
| 42 |
$constants = self::getConstantValues(); |
| 43 |
if (\is_null($name) || !\in_array($name, $constants)) { |
| 44 |
throw new InvalidArgumentException('MetadataEnvelope fields must' . ' must match a predefined offset; use the header constants.'); |
| 45 |
} |
| 46 |
$this->data[$name] = $value; |
| 47 |
} |
| 48 |
#[\ReturnTypeWillChange] |
| 49 |
public function jsonSerialize() |
| 50 |
{ |
| 51 |
return $this->data; |
| 52 |
} |
| 53 |
} |
| 54 |
|