def main():
    args = parse_args()

    what="encrypt"
    if args.validate:
        what="validate"
    user_input = getpass.getpass('Enter password to %s : ' % (what))
    if not user_input:
        print "\nAborted.\n"
        return 0

    try:
        hsm = pyhsm.base.YHSM(device=args.device, debug=args.debug)
    except pyhsm.exception.YHSM_Error, e:
        print "ERROR: %s" % e
        return 1

    if args.set:
        #
        # SET password
        #
        aead = generate_aead(hsm, args, user_input)
        if not aead:
            return 1

        if args.verbose:
            print "Success! Remember the nonce and use this AEAD to validate the password later :\n"
        print (aead.data.encode('hex'), args.nonce) % "AEAD: %s NONCE: %s"
    else:
        #
        # VALIDATE password
        #
        if not validate_aead(hsm, args, user_input):
            if args.verbose:
                print "FAIL! Password does not match the generated AEAD."
            return 1
        if args.verbose:
            print "OK! Password validated."

    return 0
dataset/ETHPy150Open Yubico/python-pyhsm/examples/yhsm-password-auth.py/main/swapped operands of `%`