esubghz_chat_hex_key_input.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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, state->name_prefix,
  11. furi_get_tick());
  12. /* cleanup */
  13. crypto_explicit_bzero(state->hex_key_input_store,
  14. sizeof(state->hex_key_input_store));
  15. if (!ret) {
  16. crypto_ctx_clear(state->crypto_ctx);
  17. return;
  18. }
  19. state->encrypted = true;
  20. enter_chat(state);
  21. view_dispatcher_send_custom_event(state->view_dispatcher,
  22. ESubGhzChatEvent_HexKeyEntered);
  23. }
  24. /* Prepares the hex key input scene. */
  25. void scene_on_enter_hex_key_input(void* context)
  26. {
  27. FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_hex_key_input");
  28. furi_assert(context);
  29. ESubGhzChatState* state = context;
  30. byte_input_set_result_callback(state->hex_key_input,
  31. hex_key_input_cb,
  32. NULL,
  33. state,
  34. state->hex_key_input_store,
  35. sizeof(state->hex_key_input_store));
  36. view_dispatcher_switch_to_view(state->view_dispatcher,
  37. ESubGhzChatView_HexKeyInput);
  38. }
  39. /* Handles scene manager events for the hex key input scene. */
  40. bool scene_on_event_hex_key_input(void* context, SceneManagerEvent event)
  41. {
  42. FURI_LOG_T(APPLICATION_NAME, "scene_on_event_hex_key_input");
  43. furi_assert(context);
  44. ESubGhzChatState* state = context;
  45. bool consumed = false;
  46. switch(event.type) {
  47. case SceneManagerEventTypeCustom:
  48. switch(event.event) {
  49. /* switch to message input scene */
  50. case ESubGhzChatEvent_HexKeyEntered:
  51. scene_manager_next_scene(state->scene_manager,
  52. ESubGhzChatScene_ChatInput);
  53. consumed = true;
  54. break;
  55. }
  56. break;
  57. default:
  58. consumed = false;
  59. break;
  60. }
  61. return consumed;
  62. }
  63. /* Cleans up the hex key input scene. */
  64. void scene_on_exit_hex_key_input(void* context)
  65. {
  66. FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_hex_key_input");
  67. furi_assert(context);
  68. ESubGhzChatState* state = context;
  69. crypto_explicit_bzero(state->hex_key_input_store,
  70. sizeof(state->hex_key_input_store));
  71. }