pub struct UserKeyManager { /* private fields */ }Expand description
Internal key manager that holds decrypted keys during user session
§Security
This struct holds sensitive cryptographic material in memory:
decrypted_keys: Contains plaintext PrivateKeys (zeroized on drop)encryption_key: Password-derived key (zeroized via manual Zeroize impl), None for passwordless users
All sensitive data is zeroized when the struct is dropped.
Implementations§
Source§impl UserKeyManager
impl UserKeyManager
Sourcepub fn new(
password: &str,
salt: &str,
encrypted_keys: Vec<UserKey>,
) -> Result<Self>
pub fn new( password: &str, salt: &str, encrypted_keys: Vec<UserKey>, ) -> Result<Self>
Create from user password and encrypted keys
Decrypts all provided keys using the password-derived encryption key.
§Arguments
password- The user’s passwordsalt- The password salt (base64 encoded string)encrypted_keys- Vec of encrypted UserKey entries from database
§Returns
A UserKeyManager with all keys decrypted and ready for use
Sourcepub fn new_passwordless(keys: Vec<UserKey>) -> Result<Self>
pub fn new_passwordless(keys: Vec<UserKey>) -> Result<Self>
Sourcepub fn get_signing_key(&self, key_id: &PublicKey) -> Option<&PrivateKey>
pub fn get_signing_key(&self, key_id: &PublicKey) -> Option<&PrivateKey>
Sourcepub fn serialize_keys(&self) -> Result<Vec<UserKey>>
pub fn serialize_keys(&self) -> Result<Vec<UserKey>>
Serialize all keys for storage
Returns UserKey metadata suitable for storing in the database. Encrypted keys are re-encrypted with the current encryption key. Unencrypted keys are serialized directly.
Keys are returned in sorted order by key_id for deterministic output.
§Returns
Vec of UserKey with updated storage, sorted by key_id
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear all decrypted keys from memory
Explicitly zeroizes all sensitive key material. Called automatically on Drop via ZeroizeOnDrop, but can be called manually to end session early.
Sourcepub fn list_key_ids(&self) -> Vec<PublicKey>
pub fn list_key_ids(&self) -> Vec<PublicKey>
List all key IDs managed by this manager
Returns key IDs sorted by creation timestamp (oldest first) for deterministic behavior.
Sourcepub fn get_key_metadata(&self, key_id: &PublicKey) -> Option<&UserKey>
pub fn get_key_metadata(&self, key_id: &PublicKey) -> Option<&UserKey>
Get metadata for a key
Sourcepub fn get_default_key_id(&self) -> Option<PublicKey>
pub fn get_default_key_id(&self) -> Option<PublicKey>
Get the default key ID
Returns the key marked as is_default=true, or falls back to the oldest key by creation timestamp if no default is explicitly set.
§Returns
The PublicKey of the default key, or None if there are no keys
Trait Implementations§
Source§impl Zeroize for UserKeyManager
impl Zeroize for UserKeyManager
impl ZeroizeOnDrop for UserKeyManager
Auto Trait Implementations§
impl Freeze for UserKeyManager
impl RefUnwindSafe for UserKeyManager
impl Send for UserKeyManager
impl Sync for UserKeyManager
impl Unpin for UserKeyManager
impl UnwindSafe for UserKeyManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more