aws_encryption_sdk.internal.utils

Helper utility functions for AWS Encryption SDK.

Functions

content_type(frame_length) Returns the appropriate content type based on the frame length.
extend_user_agent_suffix(user_agent, suffix) Adds a suffix to the provided user agent.
get_aad_content_string(content_type, …) Prepares the appropriate Body AAD Value for a message body.
message_id() Generates a new message ID.
prep_stream_data(data) Takes an input str, bytes, io.IOBase, or file object and returns an appropriate stream for _EncryptionStream objects.
prepare_data_keys(primary_master_key, …) Prepares a DataKey to be used for encrypting message and list of EncryptedDataKey objects to be serialized into header.
source_data_key_length_check(…) Validates that the supplied source_data_key’s data_key is the correct length for the supplied algorithm’s kdf_input_len value.
validate_frame_length(frame_length, algorithm) Validates that frame length is within the defined limits and is compatible with the selected algorithm.

Classes

ROStream
aws_encryption_sdk.internal.utils.content_type(frame_length)

Returns the appropriate content type based on the frame length.

Parameters:frame_length (int) – Message frame length
Returns:Appropriate content type based on frame length
Return type:aws_encryption_sdk.identifiers.ContentType
aws_encryption_sdk.internal.utils.validate_frame_length(frame_length, algorithm)

Validates that frame length is within the defined limits and is compatible with the selected algorithm.

Parameters:
Raises:
aws_encryption_sdk.internal.utils.message_id()

Generates a new message ID.

Returns:Message ID
Return type:bytes
aws_encryption_sdk.internal.utils.get_aad_content_string(content_type, is_final_frame)

Prepares the appropriate Body AAD Value for a message body.

Parameters:
Returns:

Appropriate AAD Content String

Return type:

bytes

Raises:

UnknownIdentityError – if unknown content type

aws_encryption_sdk.internal.utils.prepare_data_keys(primary_master_key, master_keys, algorithm, encryption_context)

Prepares a DataKey to be used for encrypting message and list of EncryptedDataKey objects to be serialized into header.

Parameters:
Return type:

tuple containing aws_encryption_sdk.structures.DataKey and set of aws_encryption_sdk.structures.EncryptedDataKey

aws_encryption_sdk.internal.utils.prep_stream_data(data)

Takes an input str, bytes, io.IOBase, or file object and returns an appropriate stream for _EncryptionStream objects.

Parameters:data (str, bytes, io.IOBase, or file) – Input data
Returns:Prepared stream
Return type:io.BytesIO
aws_encryption_sdk.internal.utils.source_data_key_length_check(source_data_key, algorithm)

Validates that the supplied source_data_key’s data_key is the correct length for the supplied algorithm’s kdf_input_len value.

Parameters:
Raises:

InvalidDataKeyError – if data key length does not match required kdf input length

aws_encryption_sdk.internal.utils.extend_user_agent_suffix(user_agent, suffix)

Adds a suffix to the provided user agent.

Parameters:
  • user_agent (str) – Existing user agent (None == not yet defined)
  • suffix (str) – Desired suffix to add to user agent
Returns:

User agent with suffix

Return type:

str