pub struct VaultStore { /* private fields */ }Expand description
The main vault handle. Create one with VaultStore::create or
VaultStore::open, then use its methods to manage secrets.
Implementations§
Source§impl VaultStore
impl VaultStore
Sourcepub fn create(
path: &Path,
password: &[u8],
environment: &str,
argon2_params: Option<&Argon2Params>,
keyfile_bytes: Option<&[u8]>,
) -> Result<Self>
pub fn create( path: &Path, password: &[u8], environment: &str, argon2_params: Option<&Argon2Params>, keyfile_bytes: Option<&[u8]>, ) -> Result<Self>
Create a brand-new vault file at path.
Generates a random salt, derives the master key from the password, and writes an empty vault to disk.
Pass None for argon2_params to use sensible defaults.
Pass Some(settings.argon2_params()) to use config values.
Pass Some(bytes) for keyfile_bytes to enable keyfile-based 2FA.
The keyfile hash is stored in the vault header so open can
verify the correct keyfile is used.
Sourcepub fn open(
path: &Path,
password: &[u8],
keyfile_bytes: Option<&[u8]>,
) -> Result<Self>
pub fn open( path: &Path, password: &[u8], keyfile_bytes: Option<&[u8]>, ) -> Result<Self>
Open an existing vault file, verifying its integrity.
Reads the binary file, derives the master key from the password + stored salt (using stored Argon2 params), and verifies the HMAC over the original bytes from disk.
If the vault was created with a keyfile, keyfile_bytes must be
provided. If the vault has no keyfile requirement, the parameter
is ignored.
Sourcepub fn from_parts(
path: PathBuf,
header: VaultHeader,
master_key: MasterKey,
) -> Self
pub fn from_parts( path: PathBuf, header: VaultHeader, master_key: MasterKey, ) -> Self
Build a VaultStore from pre-constructed parts.
Used by rotate-key to create a new store with a new master key
without writing to disk first.
Sourcepub fn set_secret(&mut self, name: &str, plaintext_value: &str) -> Result<()>
pub fn set_secret(&mut self, name: &str, plaintext_value: &str) -> Result<()>
Add or update a secret.
The plaintext value is encrypted with a per-secret key derived from the master key + secret name. The per-secret key is zeroized immediately after use.
Sourcepub fn get_secret(&self, name: &str) -> Result<String>
pub fn get_secret(&self, name: &str) -> Result<String>
Decrypt and return the plaintext value of a secret.
The per-secret key is zeroized after decryption.
Sourcepub fn delete_secret(&mut self, name: &str) -> Result<()>
pub fn delete_secret(&mut self, name: &str) -> Result<()>
Remove a secret from the vault.
Sourcepub fn list_secrets(&self) -> Vec<SecretMetadata>
pub fn list_secrets(&self) -> Vec<SecretMetadata>
List metadata for all secrets, sorted by name.
Sourcepub fn get_all_secrets(&self) -> Result<HashMap<String, String>>
pub fn get_all_secrets(&self) -> Result<HashMap<String, String>>
Decrypt all secrets and return them as a name -> plaintext map.
Used by the run command to inject secrets into a child process.
Sourcepub fn save(&mut self) -> Result<()>
pub fn save(&mut self) -> Result<()>
Serialize the vault and write it to disk atomically.
Computes a fresh HMAC over the header + secrets JSON and writes the full binary envelope via temp-file + rename.
Sourcepub fn environment(&self) -> &str
pub fn environment(&self) -> &str
Returns the environment name (e.g. “dev”).
Sourcepub fn secret_count(&self) -> usize
pub fn secret_count(&self) -> usize
Returns the number of secrets in the vault.
Sourcepub fn created_at(&self) -> DateTime<Utc>
pub fn created_at(&self) -> DateTime<Utc>
Returns the vault creation timestamp.
Sourcepub fn contains_key(&self, name: &str) -> bool
pub fn contains_key(&self, name: &str) -> bool
Returns true if the vault contains a secret with the given name.
This is a metadata-only check — no decryption is performed.
Sourcepub fn header(&self) -> &VaultHeader
pub fn header(&self) -> &VaultHeader
Returns a reference to the vault header.
Useful for inspecting stored Argon2 params, keyfile hash, etc.