in src/dynamodb_encryption_sdk/internal/formatting/material_description.py [0:0]
def deserialize(serialized_material_description):
# type: (dynamodb_types.BINARY_ATTRIBUTE) -> Dict[Text, Text]
"""Deserialize a serialized material description attribute into a material description dictionary.
:param dict serialized_material_description: DynamoDB attribute value containing serialized material description.
:returns: Material description dictionary
:rtype: dict
:raises InvalidMaterialDescriptionError: if malformed version
:raises InvalidMaterialDescriptionVersionError: if unknown version is found
"""
try:
# for some reason pylint can't follow the Enum member attributes
_raw_material_description = serialized_material_description[
Tag.BINARY.dynamodb_tag # pylint: disable=no-member
]
material_description_bytes = io.BytesIO(_raw_material_description)
total_bytes = len(_raw_material_description)
except (TypeError, KeyError):
message = "Invalid material description"
_LOGGER.exception(message)
raise InvalidMaterialDescriptionError(message)
# We don't currently do anything with the version, but do check to make sure it is the one we know about.
_read_version(material_description_bytes)
material_description = {}
try:
while material_description_bytes.tell() < total_bytes:
name = to_str(decode_value(material_description_bytes))
value = to_str(decode_value(material_description_bytes))
material_description[name] = value
except struct.error:
message = "Invalid material description"
_LOGGER.exception(message)
raise InvalidMaterialDescriptionError(message)
return material_description