common.h 4.0 KB

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