import hashlib


def compute_checksum(path, algorithm: str) -> str:
    """ Generates a hex digest using specified algorithm for a file. """
    buffer_size = 65536

    hash_builder = hashlib.new(algorithm)

    with open(path, 'rb') as f:
        while True:
            data = f.read(buffer_size)
            if not data:
                break
            hash_builder.update(data)

    return hash_builder.hexdigest()