From eae2d8ee10ab65e4a269bae030f417e8b37023d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sun, 29 Dec 2024 19:02:52 +0100 Subject: [PATCH] Trying checksum with encryption --- heed/src/envs/env_open_options.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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(()) }