list.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "list.h"
  2. #include <cli/cli.h>
  3. #include <stdlib.h>
  4. #include "../../../list/list.h"
  5. #include "../../../../types/token_info.h"
  6. #include "../../../config/constants.h"
  7. static char* get_algo_as_cstr(TokenHashAlgo algo) {
  8. switch(algo) {
  9. case SHA1:
  10. return TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME;
  11. case SHA256:
  12. return TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME;
  13. case SHA512:
  14. return TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME;
  15. }
  16. return "UNKNOWN";
  17. }
  18. static uint8_t get_digits_as_int(TokenDigitsCount digits) {
  19. switch(digits) {
  20. case TOTP_6_DIGITS:
  21. return 6;
  22. case TOTP_8_DIGITS:
  23. return 8;
  24. }
  25. return 6;
  26. }
  27. void totp_cli_handle_list_command(PluginState* plugin_state) {
  28. if (plugin_state->tokens_list == NULL) {
  29. printf("There are no tokens");
  30. return;
  31. }
  32. ListNode* node = plugin_state->tokens_list;
  33. printf("+-----+-----------------------------+--------+--------+\r\n");
  34. printf("| %-*s | %-*s | %-*s | %-s |\r\n", 3, "#", 27, "Name", 6, "Algo", "Digits");
  35. printf("+-----+-----------------------------+--------+--------+\r\n");
  36. uint16_t index = 1;
  37. while(node != NULL) {
  38. TokenInfo* token_info = (TokenInfo* )node->data;
  39. token_info_get_digits_count(token_info);
  40. printf("| %-3" PRIu16 " | %-27.27s | %-6s | %-6" PRIu8 " |\r\n", index, token_info->name, get_algo_as_cstr(token_info->algo), get_digits_as_int(token_info->digits));
  41. node = node->next;
  42. index++;
  43. }
  44. printf("+-----+-----------------------------+--------+--------+\r\n");
  45. }