Struct abcrypt::Encryptor

source ·
pub struct Encryptor<'m> { /* private fields */ }
Expand description

Encryptor for the abcrypt encrypted data format.

Implementations§

source§

impl<'m> Encryptor<'m>

source

pub fn new( plaintext: &'m impl AsRef<[u8]>, passphrase: impl AsRef<[u8]> ) -> Result<Self>

Available on crate feature 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();
source

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.

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();
source

pub fn encrypt(&self, buf: impl AsMut<[u8]>)

Encrypts the plaintext into buf.

Panics

Panics if any of the following are true:

  • buf and 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);
source

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

Available on crate feature 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(32, 3, 4, None).unwrap();
let cipher = Encryptor::with_params(data, passphrase, params).unwrap();
let ciphertext = cipher.encrypt_to_vec();
source

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§

source§

impl<'m> Clone for Encryptor<'m>

source§

fn clone(&self) -> Encryptor<'m>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'m> Debug for Encryptor<'m>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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

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

§

fn vzip(self) -> V