esubghz_chat_hex_key_input.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "../esubghz_chat_i.h"
  2. /* Sets the entered bytes as the key and sends a HexKeyEntered event to the
  3. * 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. 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 frequency input scene */
  49. case ESubGhzChatEvent_HexKeyEntered:
  50. scene_manager_next_scene(state->scene_manager,
  51. ESubGhzChatScene_FreqInput);
  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. }