Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

An encrypted store bound to a config and its recipient list.

Implementations§

Source§

impl Store

Source

pub fn open(config: Config) -> Result<Self>

Opens an existing store and loads its recipients. Does not unlock the identity, so the returned store can write but not yet read secrets.

§Errors
Source

pub fn create( config: Config, owner: &Identity, extra: &[Recipient], ) -> Result<Self>

Creates a brand-new store, writing .age-recipients with the owner’s public key plus any extra recipients.

§Errors
Source

pub fn root(&self) -> &Path

Returns the absolute store directory.

Source

pub fn recipients(&self) -> &[Recipient]

Returns the configured recipient list.

Source

pub fn exists(&self, logical: &str) -> bool

Returns true if a secret exists at logical.

Source

pub fn set(&self, logical: &str, secret: &Secret) -> Result<()>

Encrypts and writes (or overwrites) secret at logical.

§Errors

Error::InvalidPath for malformed paths; Error::Io / Error::Encrypt on failure.

Source

pub fn insert(&self, logical: &str, secret: &Secret) -> Result<()>

Inserts a new secret, failing with Error::SecretExists if present.

§Errors

See set plus Error::SecretExists.

Source

pub fn get(&self, logical: &str, identity: &Identity) -> Result<Secret>

Reads and decrypts the secret at logical.

§Errors

Error::InvalidPath, Error::SecretNotFound, or Error::Decrypt / Error::Io on failure.

Source

pub fn delete(&self, logical: &str) -> Result<()>

Deletes the secret at logical, pruning now-empty parent directories.

§Errors

Error::SecretNotFound if the file is absent; Error::Io otherwise.

Source

pub fn rename(&self, from: &str, to: &str, identity: &Identity) -> Result<()>

Renames a secret: decrypts it, re-binds the envelope to to, re-encrypts, writes the destination, then removes the source. Needs the identity because the path binding lives inside the ciphertext.

§Errors

Error::SecretNotFound if from is absent, Error::SecretExists if to exists, Error::InvalidPath for malformed paths, or Error::Decrypt / Error::Tampered reading the source.

Source

pub fn copy(&self, from: &str, to: &str, identity: &Identity) -> Result<()>

Copies a secret: decrypts it, re-binds the envelope to to, re-encrypts, and writes the destination. Needs the identity for the same reason as rename.

§Errors

Same as rename, minus pruning.

Source

pub fn list(&self, prefix: &str) -> Result<Vec<String>>

Lists logical paths under prefix ("" for all), sorted.

§Errors

Error::Io on directory traversal failures.

Source

pub fn grep( &self, query: &str, identity: Option<&Identity>, ) -> Result<Vec<String>>

Searches paths (always) and decrypted contents (when identity is Some) case-insensitively for query.

§Errors

Error::Io / Error::Decrypt on failure when scanning contents.

Source

pub fn set_recipients( &mut self, new_recipients: Vec<Recipient>, identity: &Identity, ) -> Result<usize>

Replaces the recipient list and re-encrypts every secret to it.

new_recipients must include identity’s public key, otherwise the user would lock themselves out.

Rotation is crash-consistent. Phase 1 re-encrypts every secret into a .ks-rotate staging tree, records the target recipients, and finally drops a READY marker — the commit point. Phase 2 moves the staged files over the live ones and flips the recipients file. A crash before READY rolls back (the live store was never touched); a crash after it rolls forward, because phase 2 is idempotent. Recovery runs automatically on the next open and can be invoked via recover_rotation.

§Errors

Error::InvalidRecipient if the user’s own key is missing, or Error::Io / Error::Decrypt during re-encryption.

Source

pub fn recover_rotation(&self) -> Result<RotationRecovery>

Detects and resolves a recipient rotation that a crash interrupted, taking the store write lock. A no-op when no staging area is present, so it is cheap to call on every open.

A rotation that crashed before its READY commit point is rolled back (the live store was never modified); one that crashed after it is rolled forward to completion. Both directions are idempotent.

§Errors

Error::Io on lock or filesystem failure, or Error::NoRecipients / Error::InvalidRecipient if a staged recipient list cannot be parsed while rolling forward.

Trait Implementations§

Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,