2022-10-28 15:34:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cli/cli.h>
|
2022-11-23 22:19:19 +00:00
|
|
|
#include "../types/plugin_state.h"
|
2022-10-28 15:34:35 +00:00
|
|
|
|
|
|
|
#define TOTP_CLI_COMMAND_NAME "totp"
|
|
|
|
|
|
|
|
#define DOCOPT_ARGUMENT(arg) "<" arg ">"
|
2022-11-23 22:19:19 +00:00
|
|
|
#define DOCOPT_MULTIPLE(arg) arg "..."
|
2022-10-28 15:34:35 +00:00
|
|
|
#define DOCOPT_OPTIONAL(param) "[" param "]"
|
|
|
|
#define DOCOPT_REQUIRED(param) "(" param ")"
|
|
|
|
#define DOCOPT_OPTION(option, value) option " " value
|
|
|
|
#define DOCOPT_SWITCH(option) option
|
|
|
|
#define DOCOPT_OPTIONS "[options]"
|
|
|
|
#define DOCOPT_DEFAULT(val) "[default: " val "]"
|
|
|
|
|
2022-11-10 05:32:21 +00:00
|
|
|
#define TOTP_CLI_PRINTF(format, ...) \
|
|
|
|
do { \
|
|
|
|
_Pragma(STRINGIFY(GCC diagnostic push)) \
|
|
|
|
_Pragma(STRINGIFY(GCC diagnostic ignored "-Wdouble-promotion")) \
|
|
|
|
printf(format, ##__VA_ARGS__); \
|
|
|
|
_Pragma(STRINGIFY(GCC diagnostic pop)) \
|
|
|
|
} while(false)
|
|
|
|
|
|
|
|
#define TOTP_CLI_DELETE_LAST_LINE() \
|
|
|
|
TOTP_CLI_PRINTF("\033[A\33[2K\r"); \
|
|
|
|
fflush(stdout)
|
|
|
|
|
|
|
|
#define TOTP_CLI_DELETE_CURRENT_LINE() \
|
|
|
|
TOTP_CLI_PRINTF("\33[2K\r"); \
|
|
|
|
fflush(stdout)
|
|
|
|
|
|
|
|
#define TOTP_CLI_DELETE_LAST_CHAR() \
|
|
|
|
TOTP_CLI_PRINTF("\b \b"); \
|
|
|
|
fflush(stdout)
|
|
|
|
|
2022-10-28 15:34:35 +00:00
|
|
|
#define TOTP_CLI_PRINT_INVALID_ARGUMENTS() \
|
|
|
|
TOTP_CLI_PRINTF( \
|
|
|
|
"Invalid command arguments. use \"help\" command to get list of available commands")
|
|
|
|
|
2022-11-23 22:19:19 +00:00
|
|
|
/**
|
|
|
|
* @brief Checks whether user is authenticated and entered correct PIN.
|
|
|
|
* If user is not authenticated it prompts user to enter correct PIN to authenticate.
|
|
|
|
* @param plugin_state application state
|
|
|
|
* @param cli reference to the firmware CLI subsystem
|
|
|
|
* @return \c true if user is already authenticated or successfully authenticated; \c false otherwise
|
|
|
|
*/
|
2022-11-10 05:32:21 +00:00
|
|
|
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);
|