secure_vault/lib.rs
1//! Simple secure vault for sensitive data
2
3/// Secure vault for protecting sensitive data
4pub struct SecureVault(String);
5
6impl SecureVault {
7 /// Create a new secure vault
8 pub fn new<T: Into<String>>(data: T) -> Self {
9 Self(data.into())
10 }
11
12 /// Access the protected data securely
13 pub fn with_secure<F, T>(&self, f: F) -> T
14 where
15 F: FnOnce(&str) -> T,
16 {
17 f(&self.0)
18 }
19}
20
21/// Macro to create protected variables
22#[macro_export]
23macro_rules! protect {
24 ($($var:ident = $value:expr;)*) => {
25 $(
26 let $var = $crate::SecureVault::new($value);
27 )*
28 };
29}