Skip to main content

Keyfile

Struct Keyfile 

Source
pub struct Keyfile {
    pub path: String,
    /* private fields */
}

Fields§

§path: String

Implementations§

Source§

impl Keyfile

Source

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.
Source

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.
Source

pub fn get_name(&self) -> Result<String, KeyFileError>

Loads the name from keyfile.name or raises an error.

Source

pub fn get_path(&self) -> Result<String, KeyFileError>

Loads the name from keyfile.path or raises an error.

Source

pub fn data(&self) -> Result<Vec<u8>, KeyFileError>

Returns the keyfile data under path.

Source

pub fn keyfile_data(&self) -> Result<Vec<u8>, KeyFileError>

Returns the keyfile data under path.

Source

pub fn env_var_name(&self) -> Result<String, KeyFileError>

Returns local environment variable key name based on Keyfile path.

Source

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.
Source

pub fn make_dirs(&self) -> Result<(), KeyFileError>

Creates directories for the path if they do not exist.

Source

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.
Source

pub fn is_readable(&self) -> Result<bool, KeyFileError>

Returns True if the file under path is readable.

Source

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.
Source

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.
Source

pub fn _may_overwrite(&self) -> bool

Asks the user if it is okay to overwrite the file.

Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

pub fn remove_password_from_env(&self) -> Result<bool, KeyFileError>

Removes the password associated with the Keyfile from the local environment.

Trait Implementations§

Source§

impl Clone for Keyfile

Source§

fn clone(&self) -> Keyfile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Display for Keyfile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, Outer> IsWrappedBy<Outer> for T
where Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,

Source§

fn from_ref(outer: &Outer) -> &T

Get a reference to the inner from the outer.

Source§

fn from_mut(outer: &mut Outer) -> &mut T

Get a mutable reference to the inner from the outer.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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<S, T> UncheckedInto<T> for S
where T: UncheckedFrom<S>,

Source§

fn unchecked_into(self) -> T

The counterpart to unchecked_from.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> JsonSchemaMaybe for T

Source§

impl<T> MaybeRefUnwindSafe for T
where T: RefUnwindSafe,