import hashlib


def hash_file(dgst, path):
    """Generate a dgst hash from file path"""
    h = hashlib.new(dgst)

    with open(path, 'rb') as file:
        for chunk in iter(lambda: file.read(4096), b""):
            h.update(chunk)
    return h.digest()