Cipher
11 months ago
Polyfill
11 months ago
AbstractCryptoClient.php
11 months ago
AbstractCryptoClientV2.php
11 months ago
AesDecryptingStream.php
11 months ago
AesEncryptingStream.php
11 months ago
AesGcmDecryptingStream.php
11 months ago
AesGcmEncryptingStream.php
11 months ago
AesStreamInterface.php
11 months ago
AesStreamInterfaceV2.php
11 months ago
DecryptionTrait.php
11 months ago
DecryptionTraitV2.php
11 months ago
EncryptionTrait.php
11 months ago
EncryptionTraitV2.php
11 months ago
KmsMaterialsProvider.php
11 months ago
KmsMaterialsProviderV2.php
11 months ago
MaterialsProvider.php
11 months ago
MaterialsProviderInterface.php
11 months ago
MaterialsProviderInterfaceV2.php
11 months ago
MaterialsProviderV2.php
11 months ago
MetadataEnvelope.php
11 months ago
MetadataStrategyInterface.php
11 months ago
MetadataEnvelope.php
62 lines
| 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 | } |
| 62 |