import json
import base64
import binascii


def validate(arg):
    """
    Validate input parameters for `left` and `right`
    :param arg: input from request
    :return: dictionary of {'data': base64encoded_stirng} if valid or
            False if not valid
    """
    if not arg:
        return False
    if isinstance(arg, str) or isinstance(arg, bytes):
        try:
            arg = json.loads(arg)
        except Exception as e:
            print(e)
            return False
    if not arg.get("data"):
        return False
    try:
        base64.b64decode(arg["data"])
    except binascii.Error:
        return False
    return arg