def _int(val: int) -> bytes:
    """
    Encode and int to a big endian byte array
    """
    if val == 0:
        return val.to_bytes(1, byteorder='big')
    return val.to_bytes((val.bit_length() + 7) // 8, byteorder='big')