spacedrive/crates/crypto/examples/secure_erase.rs
Vítor Vasconcellos 16354b0f72
Fix a couple of tests after #2218 (#2219)
- Fix some rust warnings
2024-03-19 02:23:42 +00:00

25 lines
628 B
Rust

use sd_crypto::rng::CryptoRng;
use std::io::{Seek, Write};
use tempfile::tempfile;
fn main() {
let mut file = tempfile().unwrap();
let data = CryptoRng::generate_vec(1048576 * 16);
file.write_all(&data).unwrap();
file.rewind().unwrap();
#[cfg(feature = "sys")]
{
use sd_crypto::sys::fs;
// Erase the file (the size would normally be obtained via `fs::Metadata::len()` or similar)
fs::erase(&mut file, 1048576 * 16, 2).unwrap();
}
// Truncate the file to a length of zero
file.set_len(0).unwrap();
// Normally you would call `fs::remove_file()` here, however `tempfile` doesn't let us do that
drop(file);
}