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 recommended Argon2 parameters according to the OWASP
Password Storage Cheat Sheet created by Params::default. This also
uses the Argon2 type created by Algorithm::default and the Argon2
version created by Version::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>
Creates a new Encryptor with the specified Params.
This uses the Argon2 type created by Algorithm::default and the
Argon2 version created by Version::default.
§Errors
Returns Err if the Argon2 context is invalid.
§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();Sourcepub fn with_context(
plaintext: &'m impl AsRef<[u8]>,
passphrase: impl AsRef<[u8]>,
argon2_type: Algorithm,
argon2_version: Version,
params: Params,
) -> Result<Self>
pub fn with_context( plaintext: &'m impl AsRef<[u8]>, passphrase: impl AsRef<[u8]>, argon2_type: Algorithm, argon2_version: Version, params: Params, ) -> Result<Self>
Creates a new Encryptor with the specified Algorithm, Version
and Params.
§Errors
Returns Err if the Argon2 context is invalid.
§Examples
let data = b"Hello, world!\n";
let passphrase = "passphrase";
let params = Params::new(32, 3, 4, None).unwrap();
let cipher =
Encryptor::with_context(data, passphrase, Algorithm::Argon2i, Version::V0x10, params)
.unwrap();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:
bufand 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(32, 3, 4, None).unwrap();
let cipher = Encryptor::with_params(data, passphrase, params).unwrap();
let mut buf = [u8::default(); 178];
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(), 178);