aws_encryption_sdk.internal.formatting.encryption_context

Components for handling serialization and deserialization of encryption context data in AWS Encryption SDK messages.

Functions

assemble_content_aad(message_id, …) Assembles the Body AAD string for a message body structure.
deserialize_encryption_context(…) Deserializes the contents of a byte string into a dictionary.
read_short(source, offset) Reads a number from a byte array.
read_string(source, offset, length) Reads a string from a byte string.
serialize_encryption_context(encryption_context) Serializes the contents of a dictionary into a byte string.
aws_encryption_sdk.internal.formatting.encryption_context.assemble_content_aad(message_id, aad_content_string, seq_num, length)

Assembles the Body AAD string for a message body structure.

Parameters:
Returns:

Properly formatted AAD bytes for message body structure.

Return type:

bytes

Raises:

SerializationError – if aad_content_string is not known

aws_encryption_sdk.internal.formatting.encryption_context.deserialize_encryption_context(serialized_encryption_context)

Deserializes the contents of a byte string into a dictionary.

Parameters:

serialized_encryption_context (bytes) – Source byte string containing serialized dictionary

Returns:

Deserialized encryption context

Return type:

dict

Raises:
aws_encryption_sdk.internal.formatting.encryption_context.read_short(source, offset)

Reads a number from a byte array.

Parameters:
  • source (bytes) – Source byte string
  • offset (int) – Point in byte string to start reading
Returns:

Read number and offset at point after read data

Return type:

tuple of ints

Raises:

SerializationError if unable to unpack

aws_encryption_sdk.internal.formatting.encryption_context.read_string(source, offset, length)

Reads a string from a byte string.

Parameters:
  • source (bytes) – Source byte string
  • offset (int) – Point in byte string to start reading
  • length (int) – Length of string to read
Returns:

Read string and offset at point after read data

Return type:

tuple of str and int

Raises:

SerializationError – if unable to unpack

aws_encryption_sdk.internal.formatting.encryption_context.serialize_encryption_context(encryption_context)

Serializes the contents of a dictionary into a byte string.

Parameters:encryption_context (dict) – Dictionary of encrytion context keys/values.
Returns:Serialized encryption context
Return type:bytes