example: use decrypt_user_ctx in decryption callback

This commit is contained in:
Harshit Malpani
2022-03-11 14:22:49 +05:30
parent 8b5ad2ab4f
commit c813de50ec
2 changed files with 8 additions and 7 deletions

View File

@@ -1,3 +1,2 @@
dependencies:
idf: ">=4.4"
espressif/esp_encrypted_img: "^2.0.1"

View File

@@ -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;