use memguard_rs::Secret;
fn main() {
let api_key_bytes: [u8; 32] = {
let mut arr = [0u8; 32];
for (i, byte) in arr.iter_mut().enumerate() {
*byte = (i as u8).wrapping_mul(7).wrapping_add(0x41);
}
arr
};
let key = Secret::new(api_key_bytes);
key.expose(|k| {
println!("API key loaded: {} bytes", k.len());
println!("First 4 bytes: {:02x?}", &k[..4]);
});
let locked_key = key.lock();
match &locked_key {
Ok(_) => println!("Memory locked — won't appear in swap"),
Err(_) => println!("Warning: could not lock memory (check ulimit -l)"),
}
println!("Key will be zeroized when it goes out of scope");
}