Skip to content

Commit

Permalink
Rework auto-freeing EVP_CIPHER_CTX
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine Pitrou <[email protected]>
  • Loading branch information
EnricoMi and pitrou authored Feb 6, 2025
1 parent fbe3a1c commit d3d46b7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cpp/src/parquet/encryption/encryption_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ class AesEncryptionContext {
virtual ~AesEncryptionContext() = default;

protected:
static inline std::function<void(EVP_CIPHER_CTX*)> ctx_deleter_ =
[](EVP_CIPHER_CTX* ctx) { EVP_CIPHER_CTX_free(ctx); };
static void DeleteCipherContext(EVP_CIPHER_CTX* ctx) {
EVP_CIPHER_CTX_free(ctx);
}

using CipherContext = std::unique_ptr<EVP_CIPHER_CTX, decltype(DeleteCipherContext)>;

static CipherContext WrapCipherContext(EVP_CIPHER_CTX* ctx) {
return CipherContext(ctx, DeleteCipherContext);
}

int32_t aes_mode_;
int32_t key_length_;
Expand Down

0 comments on commit d3d46b7

Please sign in to comment.