def generate_aead(hsm, args, password):
    """
    Generate an AEAD using the YubiHSM.
    """
    try:
        pw = password.ljust(args.min_len, chr(0x0))
        return hsm.generate_aead_simple(args.nonce.decode('hex'), args.key_handle, pw)
    except pyhsm.exception.YHSM_CommandFailed, e:
        if e.status_str == 'YHSM_FUNCTION_DISABLED':
            print "ERROR: The key handle %s is not permitted to YSM_AEAD_GENERATE." % (args.key_handle)
            return None
        else:
            print "ERROR: %s" % (e.reason)
dataset/ETHPy150Open Yubico/python-pyhsm/examples/yhsm-password-auth.py/generate_aead/original