pub struct CachedPassphraseProvider { /* private fields */ }Expand description
A PassphraseProvider that caches passphrases from an inner provider.
Cached values are stored in Zeroizing<String> for automatic zeroing on drop
and expire after the configured TTL (time-to-live).
This is useful for agent sessions where prompting for every signing operation would be disruptive, but credentials shouldn’t persist indefinitely.
§Security Considerations
- Cached passphrases are wrapped in
Zeroizing<String>for secure memory cleanup - TTL prevents stale credentials from persisting
- Call
clear_cache()on logout or lock events
Implementations§
Source§impl CachedPassphraseProvider
impl CachedPassphraseProvider
Sourcepub fn new(
inner: Arc<dyn PassphraseProvider + Send + Sync>,
ttl: Duration,
) -> Self
pub fn new( inner: Arc<dyn PassphraseProvider + Send + Sync>, ttl: Duration, ) -> Self
Creates a new CachedPassphraseProvider wrapping the given provider.
§Arguments
inner- The underlying provider to fetch passphrases from on cache missttl- How long cached passphrases remain valid before expiring
Sourcepub fn unlock(&self, passphrase: &str)
pub fn unlock(&self, passphrase: &str)
Pre-fill the cache with a passphrase for session-based unlock.
This allows callers to unlock once and re-use the passphrase for the configured TTL without re-prompting. The passphrase is stored only in Rust memory (never crosses FFI boundary after this call).
The default prompt key is used so all subsequent signing operations that use the same prompt will hit the cache.
Sourcepub fn remaining_ttl(&self) -> Option<Duration>
pub fn remaining_ttl(&self) -> Option<Duration>
Returns the remaining TTL in seconds, or None if no cached passphrase.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clears all cached passphrases.
Call this on logout, lock, or when the session ends to ensure cached credentials don’t persist in memory.
Trait Implementations§
Source§impl PassphraseProvider for CachedPassphraseProvider
impl PassphraseProvider for CachedPassphraseProvider
Source§fn get_passphrase(
&self,
prompt_message: &str,
) -> Result<Zeroizing<String>, AgentError>
fn get_passphrase( &self, prompt_message: &str, ) -> Result<Zeroizing<String>, AgentError>
Source§fn on_incorrect_passphrase(&self, prompt_message: &str)
fn on_incorrect_passphrase(&self, prompt_message: &str)
prompt_message was wrong. Read more