esubghz_chat_hex_key_input.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "../esubghz_chat_i.h"
  2. /* Sets the entered bytes as the key, enters the chat and sends a HexKeyEntered
  3. * event to the scene manager. */
  4. static void hex_key_input_cb(void* context)
  5. {
  6. furi_assert(context);
  7. ESubGhzChatState* state = context;
  8. /* initiate the crypto context */
  9. bool ret = crypto_ctx_set_key(state->crypto_ctx,
  10. state->hex_key_input_store);
  11. /* cleanup */
  12. crypto_explicit_bzero(state->hex_key_input_store,
  13. sizeof(state->hex_key_input_store));
  14. if (!ret) {
  15. crypto_ctx_clear(state->crypto_ctx);
  16. return;
  17. }
  18. state->encrypted = true;
  19. enter_chat(state);
  20. view_dispatcher_send_custom_event(state->view_dispatcher,
  21. ESubGhzChatEvent_HexKeyEntered);
  22. }
  23. /* Prepares the hex key input scene. */
  24. void scene_on_enter_hex_key_input(void* context)
  25. {
  26. FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_hex_key_input");
  27. furi_assert(context);
  28. ESubGhzChatState* state = context;
  29. byte_input_set_result_callback(state->hex_key_input,
  30. hex_key_input_cb,
  31. NULL,
  32. state,
  33. state->hex_key_input_store,
  34. sizeof(state->hex_key_input_store));
  35. view_dispatcher_switch_to_view(state->view_dispatcher,
  36. ESubGhzChatView_HexKeyInput);
  37. }
  38. /* Handles scene manager events for the hex key input scene. */
  39. bool scene_on_event_hex_key_input(void* context, SceneManagerEvent event)
  40. {
  41. FURI_LOG_T(APPLICATION_NAME, "scene_on_event_hex_key_input");
  42. furi_assert(context);
  43. ESubGhzChatState* state = context;
  44. bool consumed = false;
  45. switch(event.type) {
  46. case SceneManagerEventTypeCustom:
  47. switch(event.event) {
  48. /* switch to message input scene */
  49. case ESubGhzChatEvent_HexKeyEntered:
  50. scene_manager_next_scene(state->scene_manager,
  51. ESubGhzChatScene_ChatInput);
  52. consumed = true;
  53. break;
  54. }
  55. break;
  56. default:
  57. consumed = false;
  58. break;
  59. }
  60. return consumed;
  61. }
  62. /* Cleans up the hex key input scene. */
  63. void scene_on_exit_hex_key_input(void* context)
  64. {
  65. FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_hex_key_input");
  66. furi_assert(context);
  67. ESubGhzChatState* state = context;
  68. crypto_explicit_bzero(state->hex_key_input_store,
  69. sizeof(state->hex_key_input_store));
  70. }