Skip to main content

VaultStore

Struct VaultStore 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn delete_secret(&mut self, name: &str) -> Result<()>

Remove a secret from the vault.

Source

pub fn list_secrets(&self) -> Vec<SecretMetadata>

List metadata for all secrets, sorted by name.

Source

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.

Source

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.

Source

pub fn path(&self) -> &Path

Returns the path to the vault file.

Source

pub fn environment(&self) -> &str

Returns the environment name (e.g. “dev”).

Source

pub fn secret_count(&self) -> usize

Returns the number of secrets in the vault.

Source

pub fn created_at(&self) -> DateTime<Utc>

Returns the vault creation timestamp.

Source

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.

Source

pub fn header(&self) -> &VaultHeader

Returns a reference to the vault header.

Useful for inspecting stored Argon2 params, keyfile hash, etc.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V