AwsEncryptionSdk.Materials.DecryptionMaterials (AWS Encryption SDK v0.7.0)
View SourceMaterials required for decryption operations.
These materials are typically provided by a Cryptographic Materials Manager (CMM) or can be constructed directly for testing purposes.
Summary
Functions
Creates new decryption materials with a plaintext data key.
Creates decryption materials for keyring/CMM use (without plaintext data key).
Sets the plaintext data key on decryption materials.
Types
Functions
@spec new(AwsEncryptionSdk.AlgorithmSuite.t(), map(), binary(), keyword()) :: t()
Creates new decryption materials with a plaintext data key.
Use this constructor when you already have a decrypted data key (e.g., for testing or when bypassing the keyring/CMM flow).
Parameters
algorithm_suite- Algorithm suite from message headerencryption_context- Encryption context from message headerplaintext_data_key- Decrypted data keyopts- Optional fields (:verification_key, :required_encryption_context_keys)
Examples
iex> suite = AwsEncryptionSdk.AlgorithmSuite.aes_256_gcm_hkdf_sha512_commit_key()
iex> key = :crypto.strong_rand_bytes(32)
iex> materials = AwsEncryptionSdk.Materials.DecryptionMaterials.new(suite, %{}, key)
iex> is_binary(materials.plaintext_data_key)
true
@spec new_for_decrypt(AwsEncryptionSdk.AlgorithmSuite.t(), map(), keyword()) :: t()
Creates decryption materials for keyring/CMM use (without plaintext data key).
The keyring will set the plaintext_data_key during on_decrypt.
Parameters
algorithm_suite- Algorithm suite from message headerencryption_context- Encryption context from message headeropts- Optional fields (:verification_key, :required_encryption_context_keys)
Examples
iex> suite = AwsEncryptionSdk.AlgorithmSuite.aes_256_gcm_hkdf_sha512_commit_key()
iex> materials = AwsEncryptionSdk.Materials.DecryptionMaterials.new_for_decrypt(suite, %{})
iex> materials.plaintext_data_key
nil
@spec set_plaintext_data_key(t(), binary()) :: {:ok, t()} | {:error, :plaintext_data_key_already_set}
Sets the plaintext data key on decryption materials.
Used by keyrings after successfully decrypting an EDK.
Returns
{:ok, updated_materials}- Data key was set{:error, :plaintext_data_key_already_set}- Data key was already present
Examples
iex> suite = AwsEncryptionSdk.AlgorithmSuite.aes_256_gcm_hkdf_sha512_commit_key()
iex> materials = AwsEncryptionSdk.Materials.DecryptionMaterials.new_for_decrypt(suite, %{})
iex> key = :crypto.strong_rand_bytes(32)
iex> {:ok, updated} = AwsEncryptionSdk.Materials.DecryptionMaterials.set_plaintext_data_key(materials, key)
iex> updated.plaintext_data_key == key
true