@@ -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,11 +201,13 @@ 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
///
209
+ /// return Ok(());
210
+ ///
204
211
/// // We close the env and check that we can read in it
205
212
/// env.prepare_for_closing().wait();
206
213
///
@@ -216,13 +223,13 @@ impl<T: TlsUsage, C: Checksum + 'static> EnvOpenOptions<T, C> {
216
223
/// options
217
224
/// .map_size(10 * 1024 * 1024) // 10MB
218
225
/// .max_dbs(3)
219
- /// .open( &env_path)?
226
+ /// .open_encrypted::<ChaCha20Poly1305, _>(key, &env_path)?
220
227
/// };
221
228
///
222
229
/// // We check that we can read the values back
223
- /// let rtxn = env.read_txn()?;
230
+ /// let mut rtxn = env.read_txn()?;
224
231
/// let db = env.open_database::<Str, Str>(&rtxn, Some("first"))?.unwrap();
225
- /// assert!(matches!(db.get(&rtxn, key1).unwrap_err(), Error::Mdb(MdbError::BadChecksum)));
232
+ /// assert!(matches!(db.get(&mut rtxn, key1).unwrap_err(), Error::Mdb(MdbError::BadChecksum)));
226
233
/// drop(rtxn);
227
234
///
228
235
/// # Ok(()) }
0 commit comments