def _generate_content_key()

in src/dynamodb_encryption_sdk/materials/wrapped.py [0:0]


    def _generate_content_key(self):
        """Generate the content encryption key and create a new material description containing
        necessary information about the content and wrapping keys.

        :returns content key and new material description
        :rtype: tuple containing DelegatedKey and dict
        """
        if self._wrapping_key is None:
            raise WrappingError("Cryptographic materials cannot be generated: no wrapping key")

        wrapping_algorithm = self.material_description.get(
            MaterialDescriptionKeys.CONTENT_KEY_WRAPPING_ALGORITHM.value,
            self._wrapping_transformation(self._wrapping_key.algorithm),
        )
        args = self._content_key_algorithm.split("/", 1)
        content_algorithm = args[0]
        try:
            content_key_length = int(args[1])
        except IndexError:
            content_key_length = None
        content_key = JceNameLocalDelegatedKey.generate(algorithm=content_algorithm, key_length=content_key_length)
        wrapped_key = self._wrapping_key.wrap(
            algorithm=wrapping_algorithm, content_key=content_key.key, additional_associated_data=None
        )
        new_material_description = self.material_description.copy()
        new_material_description.update(
            {
                MaterialDescriptionKeys.WRAPPED_DATA_KEY.value: base64.b64encode(wrapped_key),
                MaterialDescriptionKeys.CONTENT_ENCRYPTION_ALGORITHM.value: self._content_key_algorithm,
                MaterialDescriptionKeys.CONTENT_KEY_WRAPPING_ALGORITHM.value: wrapping_algorithm,
            }
        )
        return content_key, new_material_description