Struct EncryptedFile

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

The structure which is used to store the encrypted buffer and the decryption keys.

Implementations§

Source§

impl EncryptedFile

Source

pub const fn new(buffer: &'static [u8], enc_type: EncryptionType) -> Self

Creates a new instance with the specified encrypted buffer and encryption type. The encryption type also stores the decryption keys which can be used to access the original data.

§Parameters
  • buffer: The buffer with the encrypted bytes. This will be the output of the encrypt_xor / encrypt_aes proc macros.
  • enc_type: The type of the encryption. This will be used to decrypt the buffer as it also stores the decryption keys for the different algorithms. If the key is randomly generated it will also be returned by the proc macro and saved.
§Returns

Returns a EncryptedFile instance which can be used to decrypt the internal buffer.

Source

pub fn decrypt(&self) -> Vec<u8>

Decrypts the internal buffer and returns it.

§Returns

Returns the decrypted buffer.

Examples found in repository?
examples/basic_aes.rs (line 7)
6fn main() {
7    println!("{:?}", NO_KEY.decrypt());
8    println!("{:?}", NO_KEY.decrypt_str());
9
10    println!("{:?}", CUSTOM_KEY.decrypt());
11    println!("{:?}", CUSTOM_KEY.decrypt_str());
12}
More examples
Hide additional examples
examples/basic_xor.rs (line 7)
6fn main() {
7    println!("{:?}", NO_KEY.decrypt());
8    println!("{:?}", NO_KEY.decrypt_str());
9
10    println!("{:?}", CUSTOM_KEY.decrypt());
11    println!("{:?}", CUSTOM_KEY.decrypt_str());
12}
Source

pub fn decrypt_str(&self) -> Result<String, FromUtf8Error>

Decrypts the internal buffer and returns it as a string.

§Returns

If the decrypted buffer is not a valid utf-8 string, an error will be returned. If it is a valid utf-8 string, it will be returned.

Examples found in repository?
examples/basic_aes.rs (line 8)
6fn main() {
7    println!("{:?}", NO_KEY.decrypt());
8    println!("{:?}", NO_KEY.decrypt_str());
9
10    println!("{:?}", CUSTOM_KEY.decrypt());
11    println!("{:?}", CUSTOM_KEY.decrypt_str());
12}
More examples
Hide additional examples
examples/basic_xor.rs (line 8)
6fn main() {
7    println!("{:?}", NO_KEY.decrypt());
8    println!("{:?}", NO_KEY.decrypt_str());
9
10    println!("{:?}", CUSTOM_KEY.decrypt());
11    println!("{:?}", CUSTOM_KEY.decrypt_str());
12}
examples/basic_folder.rs (line 18)
5fn main() {
6    for (name, _) in FOLDER.files {
7        println!("file_name: {:?}", name);
8    }
9
10    println!(
11        "found 'examples/basic_folder': {:?}",
12        FOLDER.get("examples/basic_folder").is_some()
13    );
14    println!(
15        "content of 'examples/example.data': {}",
16        FOLDER
17            .get("example.data")
18            .map(|file| file.decrypt_str().expect("Failed to decrypt content"))
19            .expect("Failed to find file")
20    )
21}

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

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

Source§

fn vzip(self) -> V