pub struct Crypto { /* private fields */ }
Expand description

A struct for encrypting/decrypting bytes or io streams.

Implementations

Creates a new Crypto instance, the given key will be used for every operation performed.

Basic function to encrypt.

Basic function to decrypt.

Encrypt a small piece of data.

Example:

use fencryption_lib::crypto::Crypto;

let my_super_key = "this_is_super_secure".as_bytes();
let my_super_secret_message = "hello :)".as_bytes();

let crypto = Crypto::new(my_super_key).unwrap();

let enc = crypto.encrypt(my_super_secret_message).unwrap();

assert_ne!(my_super_secret_message, enc);

Decrypt a small piece of data.

Example:

use fencryption_lib::crypto::Crypto;

let my_super_key = "this_is_super_secure".as_bytes();
let my_super_secret_message = "hello :)".as_bytes();

let crypto = Crypto::new(my_super_key).unwrap();

let enc = crypto.encrypt(my_super_secret_message).unwrap();
let dec = crypto.decrypt(&enc).unwrap();

assert_eq!(my_super_secret_message, dec);

Encrypt a stream from a source and a destination (both fs::File).

Example:

(See TmpDir)

use fencryption_lib::crypto::Crypto;
use fencryption_lib::tmp::TmpDir;

let my_super_key = b"this_is_super_secure";
let my_super_secret_message = b"hello :)";

let crypto = Crypto::new(my_super_key).unwrap();

// Creates a temporary directory
let tmp_dir = TmpDir::new().unwrap();

// tmp_dir.write_file is akin to std::fs::write
tmp_dir
    .write_file("plain", my_super_secret_message)
    .unwrap();
crypto
    .encrypt_stream(
        // tmp_dir.open_file is akin to std::fs::File::open
        &mut tmp_dir.open_file("plain").unwrap(),
        // tmp_dir.create_file is akin to std::fs::File::create
        &mut tmp_dir.create_file("enc").unwrap(),
    )
    .unwrap();

Decrypt a stream from a source and a destination (both fs::File).

Example:

(See TmpDir)

use fencryption_lib::crypto::Crypto;
use fencryption_lib::tmp::TmpDir;

let my_super_key = b"this_is_super_secure";
let my_super_secret_message = b"hello :)";

let crypto = Crypto::new(my_super_key).unwrap();

// Creates a temporary directory
let tmp_dir = TmpDir::new().unwrap();

// tmp_dir.write_file is akin to std::fs::write
tmp_dir
    .write_file("plain", my_super_secret_message)
    .unwrap();
crypto
    .encrypt_stream(
        // tmp_dir.open_file is akin to std::fs::File::open
        &mut tmp_dir.open_file("plain").unwrap(),
        // tmp_dir.create_file is akin to std::fs::File::create
        &mut tmp_dir.create_file("enc").unwrap(),
    )
    .unwrap();

crypto
    .decrypt_stream(
        // tmp_dir.open_file is akin to std::fs::File::open
        &mut tmp_dir.open_file("enc").unwrap(),
        // tmp_dir.create_file is akin to std::fs::File::create
        &mut tmp_dir.create_file("dec").unwrap(),
    )
    .unwrap();

assert_eq!(tmp_dir.read_file("dec").unwrap(), my_super_secret_message);

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.