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
impl FileEncryption
Sourcepub fn new(file_path: String, key: String) -> Self
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);Sourcepub fn create(path: &str) -> Result<()>
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);Sourcepub fn edit(&self) -> Result<()>
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.
Sourcepub fn decrypt(&self) -> Result<String>
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()?;Sourcepub fn encrypt(&self, contents: &[u8]) -> Result<String>
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§
impl Freeze for FileEncryption
impl RefUnwindSafe for FileEncryption
impl Send for FileEncryption
impl Sync for FileEncryption
impl Unpin for FileEncryption
impl UnwindSafe for FileEncryption
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
Mutably borrows from an owned value. Read more