From 85088c59fcf0c562afcdb805c35d732de2a49ccb Mon Sep 17 00:00:00 2001 From: svost Date: Fri, 11 Mar 2016 11:13:49 +0300 Subject: [PATCH] Ies_ctx_t - move to try catch block --- src/ecies.cpp | 21 +++++++++++++-------- 1 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ecies.cpp b/src/ecies.cpp index 39fe2d7..4d72bfd 100644 --- a/src/ecies.cpp +++ b/src/ecies.cpp @@ -556,12 +556,17 @@ unsigned char * ecies_decrypt(const ies_ctx_t *ctx, const cryptogram_t *cryptogr ies_ctx_t *create_context(EC_KEY *user_key) { - ies_ctx_t* ctx = (ies_ctx_t*) malloc(sizeof(ies_ctx_t)); - ctx->cipher = EVP_aes_128_cbc(); - ctx->md = EVP_sha1(); - ctx->kdf_md = EVP_sha1(); - ctx->stored_key_length = 33; - ctx->user_key = user_key; - - return ctx; + try { + ies_ctx_t* ctx = new ies_ctx_t; + ctx->cipher = EVP_aes_128_cbc(); + ctx->md = EVP_sha1(); + ctx->kdf_md = EVP_sha1(); + ctx->stored_key_length = 33; + ctx->user_key = user_key; + return ctx; + } + catch (const std::bad_alloc& e) { + printf("Error: %s in %s:%d\n", e.what(), __FILE__, __LINE__); + return NULL; + } } -- 1.7.1