def search_for_oath_code(hsm, key_handle, nonce, aead, counter, user_code, look_ahead=<NUM_LIT:1>):
key_handle = pyhsm.util.input_validate_key_handle(key_handle)<EOL>nonce = pyhsm.util.input_validate_nonce(nonce, pad = False)<EOL>aead = pyhsm.util.input_validate_aead(aead)<EOL>counter = pyhsm.util.input_validate_int(counter, '<STR_LIT>')<EOL>user_code = pyhsm.util.input_validate_int(user_code, '<STR_LIT>')<EOL>hsm.load_temp_key(nonce, key_handle, aead)<EOL>for j in xrange(look_ahead):<EOL><INDENT>this_counter = counter + j<EOL>secret = struct.pack("<STR_LIT>", this_counter)<EOL>hmac_result = hsm.hmac_sha1(pyhsm.defines.YSM_TEMP_KEY_HANDLE, secret).get_hash()<EOL>this_code = truncate(hmac_result)<EOL>if this_code == user_code:<EOL><INDENT>return this_counter + <NUM_LIT:1><EOL><DEDENT><DEDENT>return None<EOL>
Try to validate an OATH HOTP OTP generated by a token whose secret key is
available to the YubiHSM through the AEAD.

The parameter `aead' is either a string, or an instance of YHSM_GeneratedAEAD.

Returns next counter value on successful auth, and None otherwise.