From 520e09b1ada58e90075d0d462876afd3b3f9f6a9 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Tue, 8 Aug 2023 19:21:14 +0300 Subject: [PATCH] adding Env::enc_env --- src/env.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/env.rs b/src/env.rs index 399065a..f8f89cb 100644 --- a/src/env.rs +++ b/src/env.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use crate::ffi_util::from_cstr; +use crate::ffi_util::{from_cstr, opt_bytes_to_ptr}; use libc::{self, c_char, c_int}; use crate::{ffi, Error}; @@ -43,7 +43,17 @@ impl Env { pub fn new() -> Result { let env = unsafe { ffi::rocksdb_create_default_env() }; if env.is_null() { - Err(Error::new("Could not create mem env".to_owned())) + Err(Error::new("Could not create default env".to_owned())) + } else { + Ok(Self(Arc::new(EnvWrapper { inner: env }))) + } + } + + /// Returns encrypted env. they key must be a 32 bytes long array of u8 + pub fn enc_env(key: [u8; 32]) -> Result { + let env = unsafe { ffi::rocksdb_create_encrypted_env(opt_bytes_to_ptr(Some(&key))) }; + if env.is_null() { + Err(Error::new("Could not create encrypted env".to_owned())) } else { Ok(Self(Arc::new(EnvWrapper { inner: env }))) }