From a397fbd0e250e986da8d6ad87036578733068e1d Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Tue, 8 Aug 2023 18:13:15 +0300 Subject: [PATCH] adding rocksdb_create_encrypted_env --- db/c.cc | 15 +++++++++++++++ include/rocksdb/c.h | 1 + 2 files changed, 16 insertions(+) diff --git a/db/c.cc b/db/c.cc index 42ddc5217..8f374d231 100644 --- a/db/c.cc +++ b/db/c.cc @@ -46,6 +46,7 @@ #include "rocksdb/utilities/write_batch_with_index.h" #include "rocksdb/write_batch.h" #include "utilities/merge_operators.h" +#include "rocksdb/env_encryption.h" using ROCKSDB_NAMESPACE::BackupEngine; using ROCKSDB_NAMESPACE::BackupEngineOptions; @@ -4874,6 +4875,20 @@ rocksdb_env_t* rocksdb_create_default_env() { return result; } +rocksdb_env_t* rocksdb_create_encrypted_env(const char* key) { + rocksdb_env_t* result = new rocksdb_env_t; + std::shared_ptr provider; + Status status = rocksdb::EncryptionProvider::CreateFromString( + ConfigOptions(), "ippcp", &provider); + assert(status.ok()); + status = + provider->AddCipher("", key, 32, false); + assert(status.ok()); + result->rep = NewEncryptedEnv(Env::Default(), provider); + result->is_default = true; + return result; +} + rocksdb_env_t* rocksdb_create_mem_env() { rocksdb_env_t* result = new rocksdb_env_t; result->rep = ROCKSDB_NAMESPACE::NewMemEnv(Env::Default()); diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index 6636b592b..98eccad7b 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -2097,6 +2097,7 @@ extern ROCKSDB_LIBRARY_API void rocksdb_dbpath_destroy(rocksdb_dbpath_t*); /* Env */ extern ROCKSDB_LIBRARY_API rocksdb_env_t* rocksdb_create_default_env(void); +extern ROCKSDB_LIBRARY_API rocksdb_env_t* rocksdb_create_encrypted_env(const char* key); extern ROCKSDB_LIBRARY_API rocksdb_env_t* rocksdb_create_mem_env(void); extern ROCKSDB_LIBRARY_API void rocksdb_env_set_background_threads( rocksdb_env_t* env, int n);