pub struct VaultManager {
pub registry: VaultRegistry,
pub open_vaults: HashMap<String, Vault>,
}Fields§
§registry: VaultRegistry§open_vaults: HashMap<String, Vault>Implementations§
Source§impl VaultManager
impl VaultManager
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Creates a new instance of the struct.
§Returns
Returns a Result containing a newly initialized instance of Self
if the operation is successful. Otherwise, it returns an error.
§Procedure
- Loads the vault registry using the
VaultRegistry::load()method. - Initializes the
open_vaultsfield as an emptyHashMap.
§Errors
This function will return an error if VaultRegistry::load() fails.
Sourcepub fn list_vaults(&self) -> Vec<&VaultInfo>
pub fn list_vaults(&self) -> Vec<&VaultInfo>
List all available vaults
Sourcepub fn create_vault(
&mut self,
name: String,
path: Option<PathBuf>,
category: VaultCategory,
description: Option<String>,
master_password: &str,
) -> Result<String>
pub fn create_vault( &mut self, name: String, path: Option<PathBuf>, category: VaultCategory, description: Option<String>, master_password: &str, ) -> Result<String>
Creates a new vault with the specified parameters and initializes it with the given master password.
§Arguments
name- AStringrepresenting the name of the vault. This will serve as the identifying label for the vault.path- An optionalPathBufspecifying the file system location where the vault will be stored. IfNoneis provided, a default location will be determined by the system.category- AVaultCategoryenum indicating the category or use case associated with this vault (e.g., personal, business).description- An optionalStringfor providing additional details or metadata about the vault.master_password- A reference to astrthat will be used to secure the freshly created vault. This master password is required for future vault access.
§Returns
Returns a Result<String>:
Ok(String)- The unique identifier (vault ID) of the newly created vault on successful creation and initialization.Err- An error is returned if vault creation, retrieval, or initialization fails.
§Errors
This function may return an error in the following scenarios:
- If the vault could not be successfully created in the registry.
- If the vault information retrieval process encounters an issue.
- If the vault initialization process fails (e.g., due to encryption setup or invalid master password).
§Panics
§Notes
- Ensure that
master_passwordis secure and not easily guessable, as it safeguards the integrity of the vault’s contents. - It is the caller’s responsibility to manage and securely store the returned vault ID for future reference.
§See Also
self.registry.create_vault- Handles the creation of the vault in the internal registry.Vault::open_or_create- Opens an existing vault or creates a new one if it does not exist.Vault::initialize- Prepares the vault for use by setting up encryption and other necessary configurations.
Sourcepub fn open_vault(
&mut self,
vault_id: &str,
master_password: &str,
) -> Result<()>
pub fn open_vault( &mut self, vault_id: &str, master_password: &str, ) -> Result<()>
Opens a vault by its identifier and unlocks it using the provided master password.
§Parameters
vault_id: A string slice representing the unique identifier of the vault to be opened.master_password: A string slice representing the master password used to unlock the vault.
§Returns
Ok(()): If the vault is successfully opened and unlocked.Err: If the vault does not exist or an error occurs during any operation (e.g., unlocking or reading the vault).
§Errors
- Returns an error if the vault with the given
vault_idis not found in the registry. - Returns an error if unlocking the vault with the
master_passwordfails. - Returns an error if there is an issue opening or creating the vault.
§Side Effects
- Adds the opened vault to the
open_vaultscollection, which keeps track of currently open vaults.
Sourcepub fn switch_active_vault(&mut self, vault_id: &str) -> Result<()>
pub fn switch_active_vault(&mut self, vault_id: &str) -> Result<()>
Switches the active vault to the specified vault ID.
This function checks if the given vault_id exists in the registry’s list of vaults.
If the vault exists, it sets the specified vault as the active vault. If the vault
does not exist, an error is returned.
§Arguments
vault_id- A string slice that holds the ID of the vault to be set as active.
§Returns
Ok(())if the active vault is successfully switched.Errif the specifiedvault_idis not found in the registry’s list of vaults or if there is an error setting the active vault.
§Errors
This function returns an error under the following conditions:
- The specified
vault_idis not found in the registry. - There is an error while calling
set_active_vault.
Sourcepub fn get_active_vault(&mut self) -> Result<&mut Vault>
pub fn get_active_vault(&mut self) -> Result<&mut Vault>
Retrieves a mutable reference to the currently active Vault.
This function checks if there is an active vault ID registered in self.registry.
If no active vault ID is set, it returns an error indicating that there is no active vault.
If an active vault ID is set but the corresponding vault is not unlocked (i.e., not present
in self.open_vaults), it returns an error indicating that the vault is not unlocked.
On success, it returns a mutable reference to the active Vault.
§Returns
Ok(&mut Vault)- A mutable reference to the activeVaultif one exists and is unlocked.Err(anyhow::Error)- An error if there is no active vault ID set or the vault is not unlocked.
§Errors
- Returns an error with the message
"No active vault"ifself.registry.active_vault_idisNone. - Returns an error with the message
"Active vault '<ID>' is not unlocked"if the active vault is not found inself.open_vaults.
§Panics
- This function will panic if
unwrap()is called and the vault corresponding to the active ID is unexpectedly missing fromself.open_vaults. However, this condition should not occur due to the priorcontains_keycheck.
Sourcepub fn close_vault(&mut self, vault_id: &str) -> Result<()>
pub fn close_vault(&mut self, vault_id: &str) -> Result<()>
Closes the vault associated with the given vault ID.
§Parameters
vault_id: A string slice that represents the unique identifier of the vault to be closed.
§Returns
Ok(())if the operation was successful.Err(e)if an error occurs (specific error type depends on the implementation ofResult).
§Errors
§Behavior
- This function removes the specified
vault_idfrom theopen_vaultscollection. - After the operation, the vault will no longer be considered open.
Sourcepub fn close_all_vaults(&mut self)
pub fn close_all_vaults(&mut self)
Close all vaults
Sourcepub fn delete_vault(&mut self, vault_id: &str, delete_file: bool) -> Result<()>
pub fn delete_vault(&mut self, vault_id: &str, delete_file: bool) -> Result<()>
Deletes a specified vault from the system.
This method performs the following operations:
- Closes the vault if it is currently open.
- Removes the vault from the registry.
- Optionally deletes the vault’s associated files from the storage if
delete_fileis set totrue.
§Arguments
vault_id- A string slice that represents the unique identifier of the vault to be deleted.delete_file- A boolean that, whentrue, ensures the associated vault files are also deleted from the system.
§Returns
Ok(())on successful deletion of the vault.Errif there is an issue with deleting the vault from the registry or associated files.
§Errors
Returns an error in the following cases:
- If there is a failure while removing the vault from the registry.
- If deleting the associated files fails when
delete_fileistrue.
Sourcepub fn import_vault(
&mut self,
vault_file: &Path,
name: String,
category: VaultCategory,
copy_file: bool,
) -> Result<String>
pub fn import_vault( &mut self, vault_file: &Path, name: String, category: VaultCategory, copy_file: bool, ) -> Result<String>
Imports a vault into the registry.
This function allows you to import a vault by specifying the path to the vault file, a name for the vault, a category, and whether you want to copy the file during the import process.
§Arguments
vault_file- A reference to the file path of the vault to be imported.name- AStringrepresenting the name to be assigned to the imported vault.category- AVaultCategoryspecifying the category of the vault.copy_file- Aboolindicating whether the vault file should be copied during the import.true: The file will be copied to the registry.false: The original file path will be used without copying.
§Returns
Returns a Result containing:
Ok(String): A success message or identifier for the imported vault.Err(_): An error if the import fails.
§Errors
This function will return an error if:
- The file at the given path cannot be accessed.
- The file cannot be imported due to issues such as invalid format or permissions.
- The registry encounters an internal error during the import process.
Sourcepub fn update_vault_info(
&mut self,
vault_id: &str,
name: Option<String>,
description: Option<String>,
category: Option<VaultCategory>,
is_favorite: Option<bool>,
) -> Result<()>
pub fn update_vault_info( &mut self, vault_id: &str, name: Option<String>, description: Option<String>, category: Option<VaultCategory>, is_favorite: Option<bool>, ) -> Result<()>
Updates the information of a vault identified by its vault_id.
This method allows updating various properties of a vault stored in the registry,
such as its name, description, category, and favorite status. Each property can
be updated optionally by passing a Some value, or left unchanged by passing None.
§Parameters
vault_id: A string slice that uniquely identifies the vault to be updated.name: AnOption<String>representing the new name of the vault. PassSome(new_name)to update the name orNoneto leave it unchanged.description: AnOption<String>representing the new description for the vault. PassSome(new_description)to update the description orNoneto leave it unchanged.category: AnOption<VaultCategory>specifying a new category for the vault. PassSome(new_category)to update the category orNoneto leave it unchanged.is_favorite: AnOption<bool>indicating whether the vault is a favorite. PassSome(true)to mark it as a favorite,Some(false)to remove it as a favorite, orNoneto leave this setting unchanged.
§Returns
Result<()>: Returns anOk(())on success, indicating that the vault’s information was successfully updated. Returns an error ifvault_iddoes not exist or if there is an issue with updating the registry.
§Errors
This method will return an error in the following cases:
- The registry fails to find the vault with the given
vault_id. - An unexpected error occurs while trying to update the vault’s information.
Sourcepub fn is_vault_open(&self, vault_id: &str) -> bool
pub fn is_vault_open(&self, vault_id: &str) -> bool
Check if a vault is currently open/unlocked
Trait Implementations§
Source§impl Debug for VaultManager
impl Debug for VaultManager
Auto Trait Implementations§
impl !RefUnwindSafe for VaultManager
impl !Sync for VaultManager
impl !UnwindSafe for VaultManager
impl Freeze for VaultManager
impl Send for VaultManager
impl Unpin for VaultManager
impl UnsafeUnpin for VaultManager
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more