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