adding Env::enc_env

master
Niko PLP 1 year ago
parent 5ac4946462
commit 520e09b1ad
  1. 14
      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<Self, Error> {
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<Self, Error> {
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 })))
}

Loading…
Cancel
Save