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
impl EncryptedFile
Sourcepub const fn new(buffer: &'static [u8], enc_type: EncryptionType) -> Self
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 theencrypt_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.
Sourcepub fn decrypt_str(&self) -> Result<String, FromUtf8Error>
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?
More examples
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§
impl Freeze for EncryptedFile
impl RefUnwindSafe for EncryptedFile
impl Send for EncryptedFile
impl Sync for EncryptedFile
impl Unpin for EncryptedFile
impl UnwindSafe for EncryptedFile
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