import requests
import ssl
import base64


def get_digest_base64(location):
    """Download the sha256sum.txt message digest file at the given
`location`.

    :return: A `string` of the base64-encoded message digest
"""
    res = requests.get(location,
                       verify=ssl.get_default_verify_paths().openssl_cafile)
    if res.status_code == 200:
        # b64encode needs a bytes type input, use the dedicated
        # 'encode' method to turn str=>bytes. The result of
        # `b64encode` is a bytes type. Later when we go to serialize
        # this with json it needs to be a str type so we will decode
        # the bytes=>str now.
        return base64.b64encode(res.text.encode()).decode()
    else:
        raise(Exception(res.reason))