diff --git a/examples/system/ota/pre_encrypted_ota/main/idf_component.yml b/examples/system/ota/pre_encrypted_ota/main/idf_component.yml index 668714a2c4..e0dcbd50a1 100644 --- a/examples/system/ota/pre_encrypted_ota/main/idf_component.yml +++ b/examples/system/ota/pre_encrypted_ota/main/idf_component.yml @@ -1,3 +1,2 @@ dependencies: - idf: ">=4.4" espressif/esp_encrypted_img: "^2.0.1" diff --git a/examples/system/ota/pre_encrypted_ota/main/pre_encrypted_ota.c b/examples/system/ota/pre_encrypted_ota/main/pre_encrypted_ota.c index 2e8a6d4925..5cad8a6bbf 100644 --- a/examples/system/ota/pre_encrypted_ota/main/pre_encrypted_ota.c +++ b/examples/system/ota/pre_encrypted_ota/main/pre_encrypted_ota.c @@ -39,15 +39,17 @@ extern const char rsa_private_pem_end[] asm("_binary_private_pem_end"); #define OTA_URL_SIZE 256 -static esp_decrypt_handle_t decrypt_handle; - static esp_err_t _decrypt_cb(decrypt_cb_arg_t *args, void *user_ctx) { + if (args == NULL || user_ctx == NULL) { + ESP_LOGE(TAG, "_decrypt_cb: Invalid argument"); + return ESP_ERR_INVALID_ARG; + } esp_err_t err; pre_enc_decrypt_arg_t pargs = {}; - pargs.data_in = (char *) args->data_in; + pargs.data_in = args->data_in; pargs.data_in_len = args->data_in_len; - err = esp_encrypted_img_decrypt_data(decrypt_handle, &pargs); + err = esp_encrypted_img_decrypt_data((esp_decrypt_handle_t *)user_ctx, &pargs); if (err != ESP_OK && err != ESP_ERR_NOT_FINISHED) { return err; } @@ -75,7 +77,7 @@ void pre_encrypted_ota_task(void *pvParameter) esp_decrypt_cfg_t cfg = {}; cfg.rsa_pub_key = rsa_private_pem_start; cfg.rsa_pub_key_len = rsa_private_pem_end - rsa_private_pem_start; - decrypt_handle = esp_encrypted_img_decrypt_start(&cfg); + esp_decrypt_handle_t decrypt_handle = esp_encrypted_img_decrypt_start(&cfg); if (!decrypt_handle) { ESP_LOGE(TAG, "OTA upgrade failed"); vTaskDelete(NULL); @@ -106,7 +108,7 @@ void pre_encrypted_ota_task(void *pvParameter) .max_http_request_size = CONFIG_EXAMPLE_HTTP_REQUEST_SIZE, #endif .decrypt_cb = _decrypt_cb, - .decrypt_user_ctx = NULL + .decrypt_user_ctx = (void *)decrypt_handle, }; esp_https_ota_handle_t https_ota_handle = NULL;