pub struct Keyfile {
pub path: String,
/* private fields */
}Fields§
§path: StringImplementations§
Source§impl Keyfile
impl Keyfile
Sourcepub fn new(
path: String,
name: Option<String>,
should_save_to_env: bool,
) -> Result<Self, KeyFileError>
pub fn new( path: String, name: Option<String>, should_save_to_env: bool, ) -> Result<Self, KeyFileError>
Creates a new Keyfile instance.
Arguments:
path (String): The file system path where the keyfile is stored.
name (Option<String>): Optional name for the keyfile. Defaults to "Keyfile" if not provided.
should_save_to_env (bool): If ``True``, saves the password to environment variables.
Returns:
keyfile (Keyfile): A new Keyfile instance.Sourcepub fn get_keypair(
&self,
password: Option<String>,
) -> Result<Keypair, KeyFileError>
pub fn get_keypair( &self, password: Option<String>, ) -> Result<Keypair, KeyFileError>
Returns the keypair from path, decrypts data if the file is encrypted.
Arguments:
password (Option<String>): The password used to decrypt the data. If ``None``, asks for user input.
Returns:
keypair (Keypair): The Keypair loaded from the file.Sourcepub fn get_name(&self) -> Result<String, KeyFileError>
pub fn get_name(&self) -> Result<String, KeyFileError>
Loads the name from keyfile.name or raises an error.
Sourcepub fn get_path(&self) -> Result<String, KeyFileError>
pub fn get_path(&self) -> Result<String, KeyFileError>
Loads the name from keyfile.path or raises an error.
Sourcepub fn keyfile_data(&self) -> Result<Vec<u8>, KeyFileError>
pub fn keyfile_data(&self) -> Result<Vec<u8>, KeyFileError>
Returns the keyfile data under path.
Sourcepub fn env_var_name(&self) -> Result<String, KeyFileError>
pub fn env_var_name(&self) -> Result<String, KeyFileError>
Returns local environment variable key name based on Keyfile path.
Sourcepub fn set_keypair(
&self,
keypair: Keypair,
encrypt: bool,
overwrite: bool,
password: Option<String>,
) -> Result<(), KeyFileError>
pub fn set_keypair( &self, keypair: Keypair, encrypt: bool, overwrite: bool, password: Option<String>, ) -> Result<(), KeyFileError>
Writes the keypair to the file and optionally encrypts data.
Arguments:
keypair (Keypair): The keypair object to be stored.
encrypt (bool): If ``True``, encrypts the keyfile data.
overwrite (bool): If ``True``, overwrites existing file without prompting.
password (Option<String>): The password used to encrypt the data. If ``None``, asks for user input.Sourcepub fn make_dirs(&self) -> Result<(), KeyFileError>
pub fn make_dirs(&self) -> Result<(), KeyFileError>
Creates directories for the path if they do not exist.
Sourcepub fn exists_on_device(&self) -> Result<bool, KeyFileError>
pub fn exists_on_device(&self) -> Result<bool, KeyFileError>
Returns True if the file exists on the device.
Returns:
readable (bool): ``True`` if the file is readable.Sourcepub fn is_readable(&self) -> Result<bool, KeyFileError>
pub fn is_readable(&self) -> Result<bool, KeyFileError>
Returns True if the file under path is readable.
Sourcepub fn is_writable(&self) -> Result<bool, KeyFileError>
pub fn is_writable(&self) -> Result<bool, KeyFileError>
Returns True if the file under path is writable.
Returns:
writable (bool): ``True`` if the file is writable.Sourcepub fn is_encrypted(&self) -> Result<bool, KeyFileError>
pub fn is_encrypted(&self) -> Result<bool, KeyFileError>
Returns True if the file under path is encrypted.
Returns:
encrypted (bool): ``True`` if the file is encrypted.Sourcepub fn _may_overwrite(&self) -> bool
pub fn _may_overwrite(&self) -> bool
Asks the user if it is okay to overwrite the file.
Sourcepub fn check_and_update_encryption(
&self,
print_result: bool,
no_prompt: bool,
) -> Result<bool, KeyFileError>
pub fn check_and_update_encryption( &self, print_result: bool, no_prompt: bool, ) -> Result<bool, KeyFileError>
Check the version of keyfile and update if needed.
Arguments:
print_result (bool): If ``True``, prints the result of the encryption check.
no_prompt (bool): If ``True``, skips user prompts during the update process.
Returns:
updated (bool): ``True`` if the keyfile was successfully updated to the latest encryption method.Sourcepub fn encrypt(&self, password: Option<String>) -> Result<(), KeyFileError>
pub fn encrypt(&self, password: Option<String>) -> Result<(), KeyFileError>
Encrypts the file under the path.
Arguments:
password (Option<String>): The password used to encrypt the data. If ``None``, asks for user input.Sourcepub fn decrypt(&self, password: Option<String>) -> Result<(), KeyFileError>
pub fn decrypt(&self, password: Option<String>) -> Result<(), KeyFileError>
Decrypts the file under the path.
Arguments:
password (Option<String>): The password used to decrypt the data. If ``None``, asks for user input.Sourcepub fn _read_keyfile_data_from_file(&self) -> Result<Vec<u8>, KeyFileError>
pub fn _read_keyfile_data_from_file(&self) -> Result<Vec<u8>, KeyFileError>
Reads the keyfile data from the file.
Returns:
keyfile_data (Vec<u8>): The keyfile data stored under the path.
Raises:
KeyFileError: Raised if the file does not exist or is not readable.Sourcepub fn _write_keyfile_data_to_file(
&self,
keyfile_data: &[u8],
overwrite: bool,
) -> Result<(), KeyFileError>
pub fn _write_keyfile_data_to_file( &self, keyfile_data: &[u8], overwrite: bool, ) -> Result<(), KeyFileError>
Writes the keyfile data to the file.
Arguments:
keyfile_data: The byte data to store under the path.
overwrite: If true, overwrites the data without asking for permission from the user. Default is false.Sourcepub fn save_password_to_env(
&self,
password: Option<String>,
) -> Result<String, KeyFileError>
pub fn save_password_to_env( &self, password: Option<String>, ) -> Result<String, KeyFileError>
Saves the key’s password to the associated local environment variable.
Arguments:
password (Option<String>): The password to save. If ``None``, asks for user input.
Returns:
encrypted_password_base64 (str): The base64-encoded encrypted password.Sourcepub fn remove_password_from_env(&self) -> Result<bool, KeyFileError>
pub fn remove_password_from_env(&self) -> Result<bool, KeyFileError>
Removes the password associated with the Keyfile from the local environment.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Keyfile
impl RefUnwindSafe for Keyfile
impl Send for Keyfile
impl Sync for Keyfile
impl Unpin for Keyfile
impl UnsafeUnpin for Keyfile
impl UnwindSafe for Keyfile
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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<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 moreSource§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
Source§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
Source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.