mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2025-12-11 20:15:30 +01:00
* Revamping crypto subcrate * Merge with main * More tweaks on crypto crate * Remove some unsused crypto references * Fix crypto erase example
24 lines
628 B
Rust
24 lines
628 B
Rust
use sd_crypto::{erase::erase_sync, rng::CryptoRng};
|
|
|
|
use std::io::{Seek, Write};
|
|
|
|
use tempfile::tempfile;
|
|
|
|
fn main() {
|
|
let mut file = tempfile().unwrap();
|
|
let mut rng = CryptoRng::new().unwrap();
|
|
let data = rng.generate_vec(1048576 * 16);
|
|
file.write_all(&data).unwrap();
|
|
|
|
file.rewind().unwrap();
|
|
|
|
// Erase the file (the size would normally be obtained via `fs::Metadata::len()` or similar)
|
|
erase_sync(&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);
|
|
}
|