AwsEncryptionSdk.Materials.EncryptedDataKey (AWS Encryption SDK v0.7.0)

View Source

Encrypted Data Key (EDK) structure.

An EDK contains a data key encrypted by a specific key provider. Each message contains one or more EDKs, allowing decryption with any of the corresponding master keys.

Fields

  • :key_provider_id - UTF-8 identifier for the key provider (e.g., "aws-kms")
  • :key_provider_info - Provider-specific key information (binary)
  • :ciphertext - The encrypted data key (binary)

Serialization Format

Per message-header.md:

| Field              | Length        | Type   |
|--------------------|---------------|--------|
| Provider ID Length | 2 bytes       | Uint16 |
| Provider ID        | Variable      | UTF-8  |
| Provider Info Len  | 2 bytes       | Uint16 |
| Provider Info      | Variable      | Binary |
| Ciphertext Length  | 2 bytes       | Uint16 |
| Ciphertext         | Variable      | Binary |

Summary

Types

t()

Encrypted Data Key structure

Functions

Deserializes an EDK from binary format.

Deserializes a list of EDKs with count prefix.

Creates a new EncryptedDataKey.

Serializes an EDK to binary format.

Serializes a list of EDKs with a count prefix.

Types

t()

@type t() :: %AwsEncryptionSdk.Materials.EncryptedDataKey{
  ciphertext: binary(),
  key_provider_id: String.t(),
  key_provider_info: binary()
}

Encrypted Data Key structure

Functions

deserialize(arg1)

@spec deserialize(binary()) :: {:ok, t(), binary()} | {:error, term()}

Deserializes an EDK from binary format.

Returns {:ok, edk, rest} on success, or {:error, reason} on failure.

deserialize_list(arg1)

@spec deserialize_list(binary()) :: {:ok, [t()], binary()} | {:error, term()}

Deserializes a list of EDKs with count prefix.

Returns {:ok, edks, rest} on success.

new(key_provider_id, key_provider_info, ciphertext)

@spec new(String.t(), binary(), binary()) :: t()

Creates a new EncryptedDataKey.

Examples

iex> AwsEncryptionSdk.Materials.EncryptedDataKey.new("aws-kms", "key-arn", <<1, 2, 3>>)
%AwsEncryptionSdk.Materials.EncryptedDataKey{
  key_provider_id: "aws-kms",
  key_provider_info: "key-arn",
  ciphertext: <<1, 2, 3>>
}

serialize(edk)

@spec serialize(t()) :: binary()

Serializes an EDK to binary format.

Format

<<provider_id_len::16-big, provider_id::binary,
  provider_info_len::16-big, provider_info::binary,
  ciphertext_len::16-big, ciphertext::binary>>

serialize_list(edks)

@spec serialize_list([t()]) :: {:ok, binary()} | {:error, :empty_edk_list}

Serializes a list of EDKs with a count prefix.

Format

<<count::16-big, edk1::binary, edk2::binary, ...>>