@@ -171,16 +171,21 @@ impl<T: TlsUsage, C: Checksum + 'static> EnvOpenOptions<T, C> {
171
171
///
172
172
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
173
173
/// 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";
174
176
///
175
177
/// fs::create_dir_all(&env_path)?;
176
178
///
179
+ /// let mut key = Key::default();
180
+ /// Argon2::default().hash_password_into(password.as_bytes(), salt.as_bytes(), &mut key)?;
181
+ ///
177
182
/// // We open the environment
178
183
/// let mut options = EnvOpenOptions::new().checksum::<Crc32Bzip2>();
179
184
/// let env = unsafe {
180
185
/// options
181
186
/// .map_size(10 * 1024 * 1024) // 10MB
182
187
/// .max_dbs(3)
183
- /// .open( &env_path)?
188
+ /// .open_encrypted::<ChaCha20Poly1305, _>(key, &env_path)?
184
189
/// };
185
190
///
186
191
/// let key1 = "first-key";
@@ -196,9 +201,9 @@ impl<T: TlsUsage, C: Checksum + 'static> EnvOpenOptions<T, C> {
196
201
/// wtxn.commit()?;
197
202
///
198
203
/// // 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));
202
207
/// drop(rtxn);
203
208
///
204
209
/// // 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> {
216
221
/// options
217
222
/// .map_size(10 * 1024 * 1024) // 10MB
218
223
/// .max_dbs(3)
219
- /// .open( &env_path)?
224
+ /// .open_encrypted::<ChaCha20Poly1305, _>(key, &env_path)?
220
225
/// };
221
226
///
222
227
/// // We check that we can read the values back
223
- /// let rtxn = env.read_txn()?;
228
+ /// let mut rtxn = env.read_txn()?;
224
229
/// 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)));
226
231
/// drop(rtxn);
227
232
///
228
233
/// # Ok(()) }
0 commit comments