diff --git a/heed/src/envs/env_open_options.rs b/heed/src/envs/env_open_options.rs index 058df729..2886697b 100644 --- a/heed/src/envs/env_open_options.rs +++ b/heed/src/envs/env_open_options.rs @@ -171,16 +171,21 @@ impl EnvOpenOptions { /// /// # fn main() -> Result<(), Box> { /// let env_path = tempfile::tempdir()?; + /// let password = "This is the password that will be hashed by the argon2 algorithm"; + /// let salt = "The salt added to the password hashes to add more security when stored"; /// /// fs::create_dir_all(&env_path)?; /// + /// let mut key = Key::default(); + /// Argon2::default().hash_password_into(password.as_bytes(), salt.as_bytes(), &mut key)?; + /// /// // We open the environment /// let mut options = EnvOpenOptions::new().checksum::(); /// let env = unsafe { /// options /// .map_size(10 * 1024 * 1024) // 10MB /// .max_dbs(3) - /// .open(&env_path)? + /// .open_encrypted::(key, &env_path)? /// }; /// /// let key1 = "first-key"; @@ -196,9 +201,9 @@ impl EnvOpenOptions { /// wtxn.commit()?; /// /// // We check that we can read the values back - /// let rtxn = env.read_txn()?; - /// assert_eq!(db.get(&rtxn, key1)?, Some(val1)); - /// assert_eq!(db.get(&rtxn, key2)?, Some(val2)); + /// let mut rtxn = env.read_txn()?; + /// assert_eq!(db.get(&mut rtxn, key1)?, Some(val1)); + /// assert_eq!(db.get(&mut rtxn, key2)?, Some(val2)); /// drop(rtxn); /// /// // We close the env and check that we can read in it @@ -216,13 +221,13 @@ impl EnvOpenOptions { /// options /// .map_size(10 * 1024 * 1024) // 10MB /// .max_dbs(3) - /// .open(&env_path)? + /// .open_encrypted::(key, &env_path)? /// }; /// /// // We check that we can read the values back - /// let rtxn = env.read_txn()?; + /// let mut rtxn = env.read_txn()?; /// let db = env.open_database::(&rtxn, Some("first"))?.unwrap(); - /// assert!(matches!(db.get(&rtxn, key1).unwrap_err(), Error::Mdb(MdbError::BadChecksum))); + /// assert!(matches!(db.get(&mut rtxn, key1).unwrap_err(), Error::Mdb(MdbError::BadChecksum))); /// drop(rtxn); /// /// # Ok(()) } diff --git a/heed/src/envs/mod.rs b/heed/src/envs/mod.rs index 08cf3b5a..e274e75b 100644 --- a/heed/src/envs/mod.rs +++ b/heed/src/envs/mod.rs @@ -328,7 +328,7 @@ unsafe extern "C" fn checksum_func_wrapper( let result = std::panic::catch_unwind(|| { let input = ffi::from_val(*src); let output = ffi::from_val_mut(*dst); - let key = if key_ptr.is_null() { None } else { Some(ffi::from_val(key_ptr)) }; + let key = if key_ptr.is_null() { None } else { Some(ffi::from_val(*key_ptr)) }; C::checksum(input, output, key) });