pub struct Encryptor<'m> { /* private fields */ }Expand description
Encryptor for the abcrypt 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]>
) -> Result<Self>
Available on crate feature alloc only.
pub fn new( plaintext: &'m impl AsRef<[u8]>, passphrase: impl AsRef<[u8]> ) -> Result<Self>
alloc only.Creates a new Encryptor.
This uses the default Argon2 parameters created by Params::default.
Errors
Returns Err if the Argon2 context is invalid.
Examples
let data = b"Hello, world!\n";
let passphrase = "passphrase";
let cipher = Encryptor::new(data, passphrase).unwrap();sourcepub fn with_params(
plaintext: &'m impl AsRef<[u8]>,
passphrase: impl AsRef<[u8]>,
params: Params
) -> Result<Self>
pub fn with_params( plaintext: &'m impl AsRef<[u8]>, passphrase: impl AsRef<[u8]>, params: Params ) -> Result<Self>
sourcepub fn encrypt(&self, buf: impl AsMut<[u8]>)
pub fn encrypt(&self, buf: impl AsMut<[u8]>)
Encrypts the plaintext into buf.
Panics
Panics if any of the following are true:
bufand the encrypted data have different lengths.- The buffer has insufficient capacity to store the resulting ciphertext.
Examples
let data = b"Hello, world!\n";
let passphrase = "passphrase";
let params = Params::new(32, 3, 4, None).unwrap();
let cipher = Encryptor::with_params(data, passphrase, params).unwrap();
let mut buf = [u8::default(); 170];
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.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(32, 3, 4, None).unwrap();
let cipher = Encryptor::with_params(data, passphrase, params).unwrap();
assert_eq!(cipher.out_len(), 170);Trait Implementations§
Auto Trait Implementations§
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