Skip to main content

Store

Struct Store 

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

Local encrypted keystore.

Private keys are encrypted with AES-256-GCM before writing to disk. The encryption key is derived from a machine-specific secret so key files are useless if copied to another machine.

v2 will delegate to OS credential stores (Secure Enclave / TPM 2.0).

Implementations§

Source§

impl Store

Source

pub fn open(dir: impl AsRef<Path>) -> Result<Self, KeyError>

Opens or creates a keystore at dir.

Source

pub fn generate(&self, set_default: bool) -> Result<KeyInfo, KeyError>

Generates a new Ed25519 keypair, encrypts and stores it. If set_default is true (or there is no current default), makes this key the default signing key.

Source

pub fn rotate( &self, predecessor_id: Option<&str>, grace_period: Duration, set_default: bool, ) -> Result<RotationResult, KeyError>

Rotate the current default key (or a specific key) to a freshly generated successor.

Mints a new Ed25519 keypair, links the predecessor to it via successor_key_id, and stamps the predecessor with a valid_until of now + grace_period. The grace window lets verifiers continue to accept signatures from the predecessor while clients catch up to the new public key.

If set_default is true (the typical case – you rotate because you want to start signing with the new key immediately), the successor becomes the default. Pass false to stage a rotation for review without flipping the active signer.

predecessor_id may be None to rotate the current default. Pass an explicit id to rotate a non-default key (e.g. a per-environment secondary).

Note on threat model: this is a graceful rotation primitive, not a revocation primitive. If the predecessor key is suspected compromised the grace_period should be Duration::ZERO (or use a future revoke() call once that lands) so the predecessor’s valid_until is in the past and any verifier honoring the metadata refuses further signatures from it.

Source

pub fn successor_chain(&self, id: &str) -> Result<Vec<KeyId>, KeyError>

Walk the rotation chain forward from id, returning the ordered list of key ids: [id, successor_of_id, ...]. The first element is always id itself. Stops at a key with no successor_key_id.

Source

pub fn valid_keys_at(&self, at_unix_secs: u64) -> Result<Vec<KeyInfo>, KeyError>

Returns the KeyInfo for every key whose valid_until is either unset or strictly after at_unix_secs. The result includes both rotated-but-still-in-grace predecessors and never-rotated keys. Useful for building a verifier’s accept-set as of a given time.

Source

pub fn default_signer(&self) -> Result<Box<dyn Signer>, KeyError>

Returns a boxed Signer for the current default key.

Source

pub fn signer(&self, id: &str) -> Result<Box<dyn Signer>, KeyError>

Returns a boxed Signer for a specific key ID.

Source

pub fn default_key_id(&self) -> Result<KeyId, KeyError>

Returns the default key ID.

Source

pub fn list(&self) -> Result<Vec<KeyInfo>, KeyError>

Lists all keys.

Source

pub fn set_default(&self, id: &str) -> Result<(), KeyError>

Sets the default signing key.

Source

pub fn public_key(&self, id: &str) -> Result<Vec<u8>, KeyError>

Returns the public key bytes for a key ID.

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