esubghz_chat_hex_key_input.c 2.2 KB

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