token_info_iterator.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #pragma once
  2. #include "../../types/token_info.h"
  3. #include <flipper_format/flipper_format.h>
  4. #include "constants.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef int TotpIteratorUpdateTokenResult;
  9. typedef TotpIteratorUpdateTokenResult (
  10. *TOTP_ITERATOR_UPDATE_TOKEN_ACTION)(TokenInfo* const token_info, const void* context);
  11. typedef struct TokenInfoIteratorContext TokenInfoIteratorContext;
  12. enum TotpIteratorUpdateTokenResults {
  13. /**
  14. * @brief Token successfully updated
  15. */
  16. TotpIteratorUpdateTokenResultSuccess = 0,
  17. /**
  18. * @brief An error ocurred during updating config file
  19. */
  20. TotpIteratorUpdateTokenResultFileUpdateFailed = -1
  21. };
  22. /**
  23. * @brief Initializes a new token info iterator
  24. * @param storage storage reference
  25. * @param config_file config file to use
  26. * @param crypto_settings crypto settings
  27. * @return Token info iterator context
  28. */
  29. TokenInfoIteratorContext* totp_token_info_iterator_alloc(
  30. Storage* storage,
  31. FlipperFormat* config_file,
  32. CryptoSettings* crypto_settings);
  33. /**
  34. * @brief Navigates iterator to the token with given index
  35. * @param context token info iterator context
  36. * @param token_index token index to navigate to
  37. * @return \c true if navigation succeeded; \c false otherwise
  38. */
  39. bool totp_token_info_iterator_go_to(TokenInfoIteratorContext* context, size_t token_index);
  40. /**
  41. * @brief Moves current token to a given new index
  42. * @param context token info iterator context
  43. * @param new_index new token index to move current token to
  44. * @return \c true if operation succeeded; \c false otherwise
  45. */
  46. bool totp_token_info_iterator_move_current_token_info(
  47. TokenInfoIteratorContext* context,
  48. size_t new_index);
  49. /**
  50. * @brief Updates current token info using given update action
  51. * @param context token info iterator context
  52. * @param update action which is responsible to make all the necessary updates to token info
  53. * @param update_context update action context
  54. * @return \c true if operation succeeded; \c false otherwise
  55. */
  56. TotpIteratorUpdateTokenResult totp_token_info_iterator_update_current_token(
  57. TokenInfoIteratorContext* context,
  58. TOTP_ITERATOR_UPDATE_TOKEN_ACTION update,
  59. const void* update_context);
  60. /**
  61. * @brief Adds new token info to the end of the list using given update action
  62. * @param context token info iterator context
  63. * @param update action which is responsible to make all the necessary updates to token info
  64. * @param update_context update action context
  65. * @return \c true if operation succeeded; \c false otherwise
  66. */
  67. TotpIteratorUpdateTokenResult totp_token_info_iterator_add_new_token(
  68. TokenInfoIteratorContext* context,
  69. TOTP_ITERATOR_UPDATE_TOKEN_ACTION update,
  70. const void* update_context);
  71. /**
  72. * @brief Remvoves current token info
  73. * @param context token info iterator context
  74. * @return \c true if operation succeeded; \c false otherwise
  75. */
  76. bool totp_token_info_iterator_remove_current_token_info(TokenInfoIteratorContext* context);
  77. /**
  78. * @brief Disposes token info iterator and releases all the resources
  79. * @param context token info iterator context
  80. */
  81. void totp_token_info_iterator_free(TokenInfoIteratorContext* context);
  82. /**
  83. * @brief Gets current token info
  84. * @param context token info iterator context
  85. * @return current token info
  86. */
  87. const TokenInfo*
  88. totp_token_info_iterator_get_current_token(const TokenInfoIteratorContext* context);
  89. /**
  90. * @brief Gets current token info index
  91. * @param context token info iterator context
  92. * @return current token info index
  93. */
  94. size_t totp_token_info_iterator_get_current_token_index(const TokenInfoIteratorContext* context);
  95. /**
  96. * @brief Gets total amount of token infos found
  97. * @param context token info iterator context
  98. * @return amount of token infos found
  99. */
  100. size_t totp_token_info_iterator_get_total_count(const TokenInfoIteratorContext* context);
  101. /**
  102. * @brief Attaches token info iterator to another config file
  103. * @param context token info iterator context
  104. * @param config_file config file reference to attach token info iterator to
  105. */
  106. void totp_token_info_iterator_attach_to_config_file(
  107. TokenInfoIteratorContext* context,
  108. FlipperFormat* config_file);
  109. #ifdef __cplusplus
  110. }
  111. #endif