AwsEncryptionSdk.Cache.CacheEntry (AWS Encryption SDK v0.7.0)

View Source

Cache entry containing cryptographic materials with usage metadata.

Fields

  • :materials - EncryptionMaterials or DecryptionMaterials
  • :creation_time - Monotonic time when entry was created (seconds)
  • :expiry_time - Monotonic time when entry expires (seconds)
  • :messages_used - Number of messages encrypted with this entry
  • :bytes_used - Number of bytes encrypted with this entry

Summary

Functions

Checks if the cache entry has exceeded usage limits.

Checks if the cache entry has expired.

Creates a new cache entry with the given materials and TTL.

Types

materials()

t()

@type t() :: %AwsEncryptionSdk.Cache.CacheEntry{
  bytes_used: non_neg_integer(),
  creation_time: integer(),
  expiry_time: integer(),
  materials: materials(),
  messages_used: non_neg_integer()
}

Functions

exceeded_limits?(entry, max_messages, max_bytes)

@spec exceeded_limits?(t(), non_neg_integer(), non_neg_integer()) :: boolean()

Checks if the cache entry has exceeded usage limits.

Parameters

  • entry - The cache entry
  • max_messages - Maximum messages allowed
  • max_bytes - Maximum bytes allowed

Examples

iex> alias AwsEncryptionSdk.Cache.CacheEntry
iex> alias AwsEncryptionSdk.Materials.EncryptionMaterials
iex> alias AwsEncryptionSdk.AlgorithmSuite
iex> suite = AlgorithmSuite.aes_256_gcm_hkdf_sha512_commit_key()
iex> materials = EncryptionMaterials.new_for_encrypt(suite, %{})
iex> entry = %CacheEntry{
...>   materials: materials,
...>   creation_time: 0,
...>   expiry_time: 1000,
...>   messages_used: 100,
...>   bytes_used: 1000
...> }
iex> CacheEntry.exceeded_limits?(entry, 50, 10000)
true

expired?(cache_entry)

@spec expired?(t()) :: boolean()

Checks if the cache entry has expired.

Examples

iex> alias AwsEncryptionSdk.Cache.CacheEntry
iex> alias AwsEncryptionSdk.Materials.EncryptionMaterials
iex> alias AwsEncryptionSdk.AlgorithmSuite
iex> suite = AlgorithmSuite.aes_256_gcm_hkdf_sha512_commit_key()
iex> materials = EncryptionMaterials.new_for_encrypt(suite, %{})
iex> entry = CacheEntry.new(materials, 300)
iex> CacheEntry.expired?(entry)
false

new(materials, max_age)

@spec new(materials(), pos_integer()) :: t()

Creates a new cache entry with the given materials and TTL.

Parameters

  • materials - EncryptionMaterials or DecryptionMaterials
  • max_age - TTL in seconds

Examples

iex> alias AwsEncryptionSdk.Cache.CacheEntry
iex> alias AwsEncryptionSdk.Materials.EncryptionMaterials
iex> alias AwsEncryptionSdk.AlgorithmSuite
iex> suite = AlgorithmSuite.aes_256_gcm_hkdf_sha512_commit_key()
iex> materials = EncryptionMaterials.new_for_encrypt(suite, %{})
iex> entry = CacheEntry.new(materials, 300)
iex> entry.messages_used
0