Skip to content

Commit

Permalink
First work on checksummed Env
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Dec 29, 2024
1 parent 68a02a2 commit 85cc8de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions heed/src/envs/env_open_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,22 @@ impl<T: TlsUsage> EnvOpenOptions<T> {
/// [^7]: <https://github.com/LMDB/lmdb/blob/b8e54b4c31378932b69f1298972de54a565185b1/libraries/liblmdb/lmdb.h#L102-L105>
/// [^8]: <http://www.lmdb.tech/doc/index.html>
pub unsafe fn open<P: AsRef<Path>>(&self, path: P) -> Result<Env<T>> {
self.raw_open_with_encryption(
self.raw_open_with_checksum_and_encryption(
path.as_ref(),
#[cfg(master3)]
None,
#[cfg(master3)]
None,
)
}

pub unsafe fn open_checksummed<P: AsRef<Path>>(&self, path: P) -> Result<Env<T>> {
self.raw_open_with_checksum_and_encryption(
path.as_ref(),
#[cfg(master3)]
None,
#[cfg(master3)]
None,
)
}

Expand Down Expand Up @@ -390,16 +402,18 @@ impl<T: TlsUsage> EnvOpenOptions<T> {
E: AeadMutInPlace + KeyInit,
P: AsRef<Path>,
{
self.raw_open_with_encryption(
self.raw_open_with_checksum_and_encryption(
path.as_ref(),
None,
Some((Some(encrypt_func_wrapper::<E>), &key, <E as AeadCore>::TagSize::U32)),
)
.map(|inner| EncryptedEnv { inner })
}

fn raw_open_with_encryption(
fn raw_open_with_checksum_and_encryption(
&self,
path: &Path,
#[cfg(master3)] sum: Option<(ffi::MDB_sum_func, u32)>,
#[cfg(master3)] enc: Option<(ffi::MDB_enc_func, &[u8], u32)>,
) -> Result<Env<T>> {
let mut lock = OPENED_ENV.write().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion heed/src/mdb/lmdb_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use ffi::{
MDB_RDONLY, MDB_RESERVE,
};
#[cfg(master3)]
pub use ffi::{mdb_env_set_encrypt, MDB_enc_func};
pub use ffi::{mdb_env_set_encrypt, MDB_enc_func, MDB_sum_func};
#[cfg(master3)]
use lmdb_master3_sys as ffi;
#[cfg(not(master3))]
Expand Down

0 comments on commit 85cc8de

Please sign in to comment.