def check_hash(path, digest, hashobj):
    """
    Compare given digest and calculated one.

    This returns True if the two digests match.
    Otherwise this returns False.

    path: Path to the input file
    digest: Expected hex digest string
    hashobj: hashlib object (e.g. hashlib.md5())
    """
    with open(path, "rb") as f_in:
        while True:
            buf = f_in.read(hashobj.block_size * 4096)
            if not buf:
                break
            hashobj.update(buf)
    return hashobj.hexdigest() == digest