pub struct Vault { /* private fields */ }Expand description
An in-memory key-value store that can be encrypted to/from the QVLT format.
Keys are stored sorted (BTreeMap) for deterministic output. Values are zeroed from memory when the vault is dropped.
Implementations§
Source§impl Vault
impl Vault
Sourcepub fn from_map(entries: BTreeMap<String, String>) -> Self
pub fn from_map(entries: BTreeMap<String, String>) -> Self
Create a vault from an existing map.
Sourcepub fn set(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> Option<String>
pub fn set( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> Option<String>
Set a key-value pair. Returns the previous value if the key existed.
Sourcepub fn delete(&mut self, key: &str) -> Option<String>
pub fn delete(&mut self, key: &str) -> Option<String>
Remove a key. Returns the value if it existed.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
Iterate over all key-value pairs (sorted by key).
Sourcepub fn entries_mut(&mut self) -> &mut BTreeMap<String, String>
pub fn entries_mut(&mut self) -> &mut BTreeMap<String, String>
Get a mutable reference to the underlying map.
Sourcepub fn to_map(&self) -> BTreeMap<String, String>
pub fn to_map(&self) -> BTreeMap<String, String>
Clone the underlying map. (Cannot move due to Drop impl that zeroes memory.)
Sourcepub fn encrypt(&self, passphrase: &str) -> Result<Vec<u8>, VaultError>
pub fn encrypt(&self, passphrase: &str) -> Result<Vec<u8>, VaultError>
Encrypt the vault into QVLT binary format.
Uses a fresh random salt and nonce each time, so calling this twice with the same data produces different ciphertext.
Sourcepub fn decrypt(data: &[u8], passphrase: &str) -> Result<Self, VaultError>
pub fn decrypt(data: &[u8], passphrase: &str) -> Result<Self, VaultError>
Decrypt a QVLT binary blob into a vault.
Returns VaultError::DecryptionFailed if the passphrase is wrong
or the data has been tampered with.
Sourcepub fn to_shell_exports(&self) -> String
pub fn to_shell_exports(&self) -> String
Format all entries as export KEY='VALUE' lines for shell eval.
Single quotes in values are escaped as '\''.