in src/dynamodb_encryption_sdk/internal/formatting/material_description.py [0:0]
def serialize(material_description):
# type: (Dict[Text, Text]) -> dynamodb_types.BINARY_ATTRIBUTE
"""Serialize a material description dictionary into a DynamodDB attribute.
:param dict material_description: Material description dictionary
:returns: Serialized material description as a DynamoDB binary attribute value
:rtype: dict
:raises InvalidMaterialDescriptionError: if invalid name or value found in material description
"""
material_description_bytes = bytearray(_MATERIAL_DESCRIPTION_VERSION)
for name, value in sorted(material_description.items(), key=lambda x: x[0]):
try:
material_description_bytes.extend(encode_value(to_bytes(name)))
material_description_bytes.extend(encode_value(to_bytes(value)))
except (TypeError, struct.error):
raise InvalidMaterialDescriptionError(
'Invalid name or value in material description: "{name}"="{value}"'.format(name=name, value=value)
)
# for some reason pylint can't follow the Enum member attributes
return {Tag.BINARY.dynamodb_tag: bytes(material_description_bytes)} # pylint: disable=no-member