details.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "details.h"
  2. #include <stdlib.h>
  3. #include <lib/toolbox/args.h>
  4. #include "../../../lib/list/list.h"
  5. #include "../../../types/token_info.h"
  6. #include "../../../services/config/constants.h"
  7. #include "../../cli_helpers.h"
  8. #include "../../common_command_arguments.h"
  9. static void print_automation_features(const TokenInfo* token_info) {
  10. if(token_info->automation_features == TOKEN_AUTOMATION_FEATURE_NONE) {
  11. TOTP_CLI_PRINTF("| %-20s | %-28.28s |\r\n", "Automation features", "None");
  12. return;
  13. }
  14. if(token_info->automation_features & TOKEN_AUTOMATION_FEATURE_ENTER_AT_THE_END) {
  15. TOTP_CLI_PRINTF(
  16. "| %-20s | %-28.28s |\r\n", "Automation features", "Type <Enter> key at the end");
  17. }
  18. }
  19. void totp_cli_command_details_docopt_commands() {
  20. TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_DETAILS ", " TOTP_CLI_COMMAND_DETAILS_ALT
  21. " Displays token details\r\n");
  22. }
  23. void totp_cli_command_details_docopt_usage() {
  24. TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " DOCOPT_REQUIRED(
  25. TOTP_CLI_COMMAND_DETAILS
  26. " | " TOTP_CLI_COMMAND_DETAILS_ALT) " " DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_INDEX) "\r\n");
  27. }
  28. void totp_cli_command_details_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
  29. if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
  30. return;
  31. }
  32. int token_number;
  33. if(!args_read_int_and_trim(args, &token_number) || token_number <= 0 ||
  34. token_number > plugin_state->tokens_count) {
  35. TOTP_CLI_PRINT_INVALID_ARGUMENTS();
  36. return;
  37. }
  38. ListNode* list_node = list_element_at(plugin_state->tokens_list, token_number - 1);
  39. TokenInfo* token_info = list_node->data;
  40. TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
  41. TOTP_CLI_PRINTF("| %-20s | %-28s |\r\n", "Property", "Value");
  42. TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
  43. TOTP_CLI_PRINTF("| %-20s | %-28d |\r\n", "Index", token_number);
  44. TOTP_CLI_PRINTF("| %-20s | %-28.28s |\r\n", "Name", token_info->name);
  45. TOTP_CLI_PRINTF(
  46. "| %-20s | %-28s |\r\n", "Hashing algorithm", token_info_get_algo_as_cstr(token_info));
  47. TOTP_CLI_PRINTF("| %-20s | %-28" PRIu8 " |\r\n", "Number of digits", token_info->digits);
  48. TOTP_CLI_PRINTF(
  49. "| %-20s | %" PRIu8 " sec.%-21s |\r\n", "Token lifetime", token_info->duration, " ");
  50. print_automation_features(token_info);
  51. TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
  52. }