common.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #pragma once
  2. #include <stdlib.h>
  3. #include "../../../types/token_info.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #define TOTP_CLI_COMMAND_ARG_NAME_PREFIX "-n"
  8. #define TOTP_CLI_COMMAND_ARG_ALGO_PREFIX "-a"
  9. #define TOTP_CLI_COMMAND_ARG_DIGITS_PREFIX "-d"
  10. #define TOTP_CLI_COMMAND_ARG_UNSECURE_PREFIX "-u"
  11. #define TOTP_CLI_COMMAND_ARG_DURATION_PREFIX "-l"
  12. #define TOTP_CLI_COMMAND_ARG_AUTOMATION_FEATURE_PREFIX "-b"
  13. #define TOTP_CLI_COMMAND_ARG_SECRET_ENCODING_PREFIX "-e"
  14. #define TOTP_CLI_COMMAND_ARG_TYPE_PREFIX "-t"
  15. #define TOTP_CLI_COMMAND_ARG_COUNTER_PREFIX "-i"
  16. /**
  17. * @brief Tries to read token hashing algo
  18. * @param token_info token info to set parsed algo to if successfully read and parsed
  19. * @param arg argument to parse
  20. * @param args rest of arguments
  21. * @param[out] parsed will be set to \c true if token hashing algo sucecssfully read and parsed; \c false otherwise
  22. * @return \c true if \c arg represents token hashing algo argument; \c false otherwise
  23. */
  24. bool totp_cli_try_read_algo(TokenInfo* token_info, FuriString* arg, FuriString* args, bool* parsed);
  25. /**
  26. * @brief Tries to read token digits count
  27. * @param token_info token info to set parsed digits count to if successfully read and parsed
  28. * @param arg argument to parse
  29. * @param args rest of arguments
  30. * @param[out] parsed will be set to \c true if token digits count sucecssfully read and parsed; \c false otherwise
  31. * @return \c true if \c arg represents token digits count argument; \c false otherwise
  32. */
  33. bool totp_cli_try_read_digits(
  34. TokenInfo* token_info,
  35. const FuriString* arg,
  36. FuriString* args,
  37. bool* parsed);
  38. /**
  39. * @brief Tries to read token duration
  40. * @param token_info token info to set parsed duration 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 duration sucecssfully read and parsed; \c false otherwise
  44. * @return \c true if \c arg represents token duration argument; \c false otherwise
  45. */
  46. bool totp_cli_try_read_duration(
  47. TokenInfo* token_info,
  48. const FuriString* arg,
  49. FuriString* args,
  50. bool* parsed);
  51. /**
  52. * @brief Tries to read token automation features
  53. * @param token_info token info to set parsed automation features 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 automation features sucecssfully read and parsed; \c false otherwise
  57. * @return \c true if \c arg represents token automation features argument; \c false otherwise
  58. */
  59. bool totp_cli_try_read_automation_features(
  60. TokenInfo* token_info,
  61. FuriString* arg,
  62. FuriString* args,
  63. bool* parsed);
  64. /**
  65. * @brief Tries to read unsecure flag
  66. * @param arg argument to parse
  67. * @param[out] parsed will be set to \c true if unsecure flag sucecssfully read and parsed; \c false otherwise
  68. * @param[out] unsecure_flag will be set to parsed unsecure flag state if read and parsed successfully
  69. * @return \c true if \c arg represents unsecure flag argument; \c false otherwise
  70. */
  71. bool totp_cli_try_read_unsecure_flag(const FuriString* arg, bool* parsed, bool* unsecure_flag);
  72. /**
  73. * @brief Tries to read plain token secret encoding
  74. * @param arg argument to parse
  75. * @param args rest of arguments
  76. * @param[out] parsed will be set to \c true if plain token secret encoding sucecssfully read and parsed; \c false otherwise
  77. * @param[out] secret_encoding will be set to parsed plain token secret encoding if read and parsed successfully
  78. * @return \c true if \c arg represents plain token secret encoding argument; \c false otherwise
  79. */
  80. bool totp_cli_try_read_plain_token_secret_encoding(
  81. FuriString* arg,
  82. FuriString* args,
  83. bool* parsed,
  84. PlainTokenSecretEncoding* secret_encoding);
  85. /**
  86. * @brief Tries to read token type
  87. * @param token_info token info to set parsed token type to if successfully read and parsed
  88. * @param arg argument to parse
  89. * @param args rest of arguments
  90. * @param parsed will be set to \c true if token type sucecssfully read and parsed; \c false otherwise
  91. * @return \c true if \c arg represents token type argument; \c false otherwise
  92. */
  93. bool totp_cli_try_read_token_type(
  94. TokenInfo* token_info,
  95. FuriString* arg,
  96. FuriString* args,
  97. bool* parsed);
  98. /**
  99. * @brief Tries to read token counter
  100. * @param token_info token info to set parsed token counter to if successfully read and parsed
  101. * @param arg argument to parse
  102. * @param args rest of arguments
  103. * @param parsed will be set to \c true if token counter sucecssfully read and parsed; \c false otherwise
  104. * @return \c true if \c arg represents token counter argument; \c false otherwise
  105. */
  106. bool totp_cli_try_read_token_counter(
  107. TokenInfo* token_info,
  108. FuriString* arg,
  109. FuriString* args,
  110. bool* parsed);
  111. #ifdef __cplusplus
  112. }
  113. #endif