@@ -171,16 +171,21 @@ impl<T: TlsUsage, C: Checksum + 'static> EnvOpenOptions<T, C> {
171171 ///
172172 /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
173173 /// let env_path = tempfile::tempdir()?;
174+ /// let password = "This is the password that will be hashed by the argon2 algorithm";
175+ /// let salt = "The salt added to the password hashes to add more security when stored";
174176 ///
175177 /// fs::create_dir_all(&env_path)?;
176178 ///
179+ /// let mut key = Key::default();
180+ /// Argon2::default().hash_password_into(password.as_bytes(), salt.as_bytes(), &mut key)?;
181+ ///
177182 /// // We open the environment
178183 /// let mut options = EnvOpenOptions::new().checksum::<Crc32Bzip2>();
179184 /// let env = unsafe {
180185 /// options
181186 /// .map_size(10 * 1024 * 1024) // 10MB
182187 /// .max_dbs(3)
183- /// .open( &env_path)?
188+ /// .open_encrypted::<ChaCha20Poly1305, _>(key, &env_path)?
184189 /// };
185190 ///
186191 /// let key1 = "first-key";
@@ -196,9 +201,9 @@ impl<T: TlsUsage, C: Checksum + 'static> EnvOpenOptions<T, C> {
196201 /// wtxn.commit()?;
197202 ///
198203 /// // We check that we can read the values back
199- /// let rtxn = env.read_txn()?;
200- /// assert_eq!(db.get(&rtxn, key1)?, Some(val1));
201- /// assert_eq!(db.get(&rtxn, key2)?, Some(val2));
204+ /// let mut rtxn = env.read_txn()?;
205+ /// assert_eq!(db.get(&mut rtxn, key1)?, Some(val1));
206+ /// assert_eq!(db.get(&mut rtxn, key2)?, Some(val2));
202207 /// drop(rtxn);
203208 ///
204209 /// // We close the env and check that we can read in it
@@ -216,13 +221,13 @@ impl<T: TlsUsage, C: Checksum + 'static> EnvOpenOptions<T, C> {
216221 /// options
217222 /// .map_size(10 * 1024 * 1024) // 10MB
218223 /// .max_dbs(3)
219- /// .open( &env_path)?
224+ /// .open_encrypted::<ChaCha20Poly1305, _>(key, &env_path)?
220225 /// };
221226 ///
222227 /// // We check that we can read the values back
223- /// let rtxn = env.read_txn()?;
228+ /// let mut rtxn = env.read_txn()?;
224229 /// let db = env.open_database::<Str, Str>(&rtxn, Some("first"))?.unwrap();
225- /// assert!(matches!(db.get(&rtxn, key1).unwrap_err(), Error::Mdb(MdbError::BadChecksum)));
230+ /// assert!(matches!(db.get(&mut rtxn, key1).unwrap_err(), Error::Mdb(MdbError::BadChecksum)));
226231 /// drop(rtxn);
227232 ///
228233 /// # Ok(()) }
0 commit comments