pub struct Encryptor<'m> { /* private fields */ }
Expand description
Encryptor for the scrypt encrypted data format.
Implementations§
Source§impl<'m> Encryptor<'m>
impl<'m> Encryptor<'m>
Sourcepub fn new(
plaintext: &'m impl AsRef<[u8]>,
passphrase: impl AsRef<[u8]>,
) -> Self
pub fn new( plaintext: &'m impl AsRef<[u8]>, passphrase: impl AsRef<[u8]>, ) -> Self
Creates a new Encryptor
.
This uses the recommended scrypt parameters according to the OWASP
Password Storage Cheat Sheet created by Params::default
.
§Examples
let data = b"Hello, world!\n";
let passphrase = "passphrase";
let cipher = Encryptor::new(data, passphrase);
Sourcepub fn with_params(
plaintext: &'m impl AsRef<[u8]>,
passphrase: impl AsRef<[u8]>,
params: Params,
) -> Self
pub fn with_params( plaintext: &'m impl AsRef<[u8]>, passphrase: impl AsRef<[u8]>, params: Params, ) -> Self
Sourcepub fn encrypt(&self, buf: &mut (impl AsMut<[u8]> + ?Sized))
pub fn encrypt(&self, buf: &mut (impl AsMut<[u8]> + ?Sized))
Encrypts the plaintext into buf
.
§Panics
Panics if any of the following are true:
buf
and the encrypted data have different lengths.- The end of the keystream will be reached with the given data length.
§Examples
let data = b"Hello, world!\n";
let passphrase = "passphrase";
let params = Params::new(10, 8, 1, Params::RECOMMENDED_LEN).unwrap();
let cipher = Encryptor::with_params(data, passphrase, params);
let mut buf = [u8::default(); 142];
cipher.encrypt(&mut buf);
Sourcepub fn encrypt_to_vec(&self) -> Vec<u8> ⓘ
Available on crate feature alloc
only.
pub fn encrypt_to_vec(&self) -> Vec<u8> ⓘ
alloc
only.Encrypts the plaintext and into a newly allocated
Vec
.
§Examples
let data = b"Hello, world!\n";
let passphrase = "passphrase";
let params = Params::new(10, 8, 1, Params::RECOMMENDED_LEN).unwrap();
let cipher = Encryptor::with_params(data, passphrase, params);
let ciphertext = cipher.encrypt_to_vec();
Sourcepub const fn out_len(&self) -> usize
pub const fn out_len(&self) -> usize
Returns the number of output bytes of the encrypted data.
§Examples
let data = b"Hello, world!\n";
let passphrase = "passphrase";
let params = Params::new(10, 8, 1, Params::RECOMMENDED_LEN).unwrap();
let cipher = Encryptor::with_params(data, passphrase, params);
assert_eq!(cipher.out_len(), 142);
Trait Implementations§
Auto Trait Implementations§
impl<'m> Freeze for Encryptor<'m>
impl<'m> RefUnwindSafe for Encryptor<'m>
impl<'m> Send for Encryptor<'m>
impl<'m> Sync for Encryptor<'m>
impl<'m> Unpin for Encryptor<'m>
impl<'m> UnwindSafe for Encryptor<'m>
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