import hashlib
import base64


def _calculate_digest(request):
    """Calculate the digest of the request body and make a string of the type expected by the
    requests-http-signature library.

    Args:
        request: The request object.

    Returns:
        digest_string (str): A string of digest.
    """
    raw_digest = hashlib.sha256(request.get_data()).digest()
    digest_string = 'SHA-256=' + base64.b64encode(raw_digest).decode()
    return digest_string