FileEncryption

Struct FileEncryption 

Source
pub struct FileEncryption { /* private fields */ }
Expand description

Represents an encryped file that we can edit the contents of while preserving the encryption.

§Examples

You can create a FileEncryption using the following code:

use street_cred::FileEncryption;

let file_name = String::from("encrypted.txt");
let key = String::from("16 byte key line");
let file_encryption = FileEncryption::new(file_name, key);

// File is decrypted, opened in your EDITOR for modification
// and once closed, re-encrypts the file if it's contents have changed.
// let result = file_encryption.edit();

// match result {
//   Ok(_) -> {},
//   Err(why) => println!("{}", why),
// }

Implementations§

Source§

impl FileEncryption

Source

pub fn new(file_path: String, key: String) -> Self

Create a new instance of FileEncryption.

§Arguments
  • file_path - Path to the encrypted file.
  • key - Key to use for encryption/decryption.
§Examples
use street_cred::FileEncryption;

let file_path = String::from("some_file.txt");
let key = String::from("425D76994EE6101105DDDA2EE2604AA0");
let file_encryption = FileEncryption::new(file_path, key);
Source

pub fn create(path: &str) -> Result<()>

Initialize a new credentials file and master key in the current directory.

§Example
use street_cred::FileEncryption;


let _ = FileEncryption::create(&file_path);
Source

pub fn edit(&self) -> Result<()>

Edit the contents of an encrypted file via your preferred EDITOR. If no EDITOR environment variable is set, will default to vim.

Source

pub fn decrypt(&self) -> Result<String>

Decrypts the contents of the FileEncryption and returns them as a tuple with three Strings.

§Examples
use street_cred::FileEncryption;

let file_path = String::from("some_file.txt");
let key = String::from("425D76994EE6101105DDDA2EE2604AA0");
let file_encryption = FileEncryption::new(file_path, key);
// let contents = file_encryption.decrypt()?;
Source

pub fn encrypt(&self, contents: &[u8]) -> Result<String>

Encrypts the contents of the FileEncryption and returns them as a String

§Examples
use street_cred::FileEncryption;

let file_path = String::from("some_file.txt");
let key = String::from("425D76994EE6101105DDDA2EE2604AA0");
let file_encryption = FileEncryption::new(file_path, key);
let contents = "a secret message";

// let encrypted_contents = file_encryption.encrypt(contents)?;

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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.