common_command_arguments.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include <stdlib.h>
  3. #include "../types/token_info.h"
  4. #include "cli_helpers.h"
  5. #define TOTP_CLI_COMMAND_ARG_NAME "name"
  6. #define TOTP_CLI_COMMAND_ARG_NAME_PREFIX "-n"
  7. #define TOTP_CLI_COMMAND_ARG_ALGO "algo"
  8. #define TOTP_CLI_COMMAND_ARG_ALGO_PREFIX "-a"
  9. #define TOTP_CLI_COMMAND_ARG_DIGITS "digits"
  10. #define TOTP_CLI_COMMAND_ARG_DIGITS_PREFIX "-d"
  11. #define TOTP_CLI_COMMAND_ARG_UNSECURE_PREFIX "-u"
  12. #define TOTP_CLI_COMMAND_ARG_DURATION "duration"
  13. #define TOTP_CLI_COMMAND_ARG_DURATION_PREFIX "-l"
  14. #define TOTP_CLI_COMMAND_ARG_AUTOMATION_FEATURE_PREFIX "-b"
  15. #define TOTP_CLI_COMMAND_ARG_AUTOMATION_FEATURE "feature"
  16. #define TOTP_CLI_COMMAND_ARG_INDEX "index"
  17. #define TOTP_CLI_COMMAND_ARG_SECRET_ENCODING_PREFIX "-e"
  18. #define TOTP_CLI_COMMAND_ARG_SECRET_ENCODING "encoding"
  19. /**
  20. * @brief Prints information about unknown argument
  21. * @param arg
  22. */
  23. void totp_cli_printf_unknown_argument(const FuriString* arg);
  24. /**
  25. * @brief Prints information about missed required argument
  26. * @param arg
  27. */
  28. void totp_cli_printf_missed_argument_value(char* arg);
  29. /**
  30. * @brief Tries to read token hashing algo
  31. * @param token_info token info to set parsed algo to if successfully read and parsed
  32. * @param arg argument to parse
  33. * @param args rest of arguments
  34. * @param[out] parsed will be set to \c true if token hashing algo sucecssfully read and parsed; \c false otherwise
  35. * @return \c true if \c arg represents token hashing algo argument; \c false otherwise
  36. */
  37. bool totp_cli_try_read_algo(TokenInfo* token_info, FuriString* arg, FuriString* args, bool* parsed);
  38. /**
  39. * @brief Tries to read token digits count
  40. * @param token_info token info to set parsed digits count to if successfully read and parsed
  41. * @param arg argument to parse
  42. * @param args rest of arguments
  43. * @param[out] parsed will be set to \c true if token digits count sucecssfully read and parsed; \c false otherwise
  44. * @return \c true if \c arg represents token digits count argument; \c false otherwise
  45. */
  46. bool totp_cli_try_read_digits(
  47. TokenInfo* token_info,
  48. const FuriString* arg,
  49. FuriString* args,
  50. bool* parsed);
  51. /**
  52. * @brief Tries to read token duration
  53. * @param token_info token info to set parsed duration to if successfully read and parsed
  54. * @param arg argument to parse
  55. * @param args rest of arguments
  56. * @param[out] parsed will be set to \c true if token duration sucecssfully read and parsed; \c false otherwise
  57. * @return \c true if \c arg represents token duration argument; \c false otherwise
  58. */
  59. bool totp_cli_try_read_duration(
  60. TokenInfo* token_info,
  61. const FuriString* arg,
  62. FuriString* args,
  63. bool* parsed);
  64. /**
  65. * @brief Tries to read token automation features
  66. * @param token_info token info to set parsed automation features to if successfully read and parsed
  67. * @param arg argument to parse
  68. * @param args rest of arguments
  69. * @param[out] parsed will be set to \c true if token automation features sucecssfully read and parsed; \c false otherwise
  70. * @return \c true if \c arg represents token automation features argument; \c false otherwise
  71. */
  72. bool totp_cli_try_read_automation_features(
  73. TokenInfo* token_info,
  74. FuriString* arg,
  75. FuriString* args,
  76. bool* parsed);
  77. /**
  78. * @brief Tries to read unsecure flag
  79. * @param arg argument to parse
  80. * @param[out] parsed will be set to \c true if unsecure flag sucecssfully read and parsed; \c false otherwise
  81. * @param[out] unsecure_flag will be set to parsed unsecure flag state if read and parsed successfully
  82. * @return \c true if \c arg represents unsecure flag argument; \c false otherwise
  83. */
  84. bool totp_cli_try_read_unsecure_flag(const FuriString* arg, bool* parsed, bool* unsecure_flag);
  85. /**
  86. * @brief Tries to read plain token secret encoding
  87. * @param arg argument to parse
  88. * @param args rest of arguments
  89. * @param[out] parsed will be set to \c true if plain token secret encoding sucecssfully read and parsed; \c false otherwise
  90. * @param[out] secret_encoding will be set to parsed plain token secret encoding if read and parsed successfully
  91. * @return \c true if \c arg represents plain token secret encoding argument; \c false otherwise
  92. */
  93. bool totp_cli_try_read_plain_token_secret_encoding(
  94. FuriString* arg,
  95. FuriString* args,
  96. bool* parsed,
  97. PlainTokenSecretEncoding* secret_encoding);