Struct abcrypt::Decryptor

source ·
pub struct Decryptor<'c> { /* private fields */ }
Expand description

Decryptor for the abcrypt encrypted data format.

Implementations§

source§

impl<'c> Decryptor<'c>

source

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

Creates a new Decryptor.

Errors

Returns Err if any of the following are true:

  • ciphertext is shorter than 156 bytes.
  • The magic number is invalid.
  • The version number is the unrecognized abcrypt version number.
  • The Argon2 parameters are invalid.
  • The Argon2 context is invalid.
  • The MAC (authentication tag) of the header is invalid.
Examples
let ciphertext = include_bytes!("../tests/data/data.txt.abcrypt");
let passphrase = "passphrase";

let cipher = Decryptor::new(&ciphertext, passphrase).unwrap();
source

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

Decrypts the ciphertext into buf.

Errors

Returns Err if the MAC (authentication tag) of the ciphertext is invalid.

Panics

Panics if buf and the decrypted data have different lengths.

Examples
let data = b"Hello, world!\n";
let ciphertext = include_bytes!("../tests/data/data.txt.abcrypt");
let passphrase = "passphrase";

let cipher = Decryptor::new(&ciphertext, passphrase).unwrap();
let mut buf = [u8::default(); 14];
cipher.decrypt(&mut buf).unwrap();
source

pub fn decrypt_to_vec(&self) -> Result<Vec<u8>>

Available on crate feature alloc only.

Decrypts the ciphertext and into a newly allocated Vec.

Errors

Returns Err if the MAC (authentication tag) of the ciphertext is invalid.

Examples
let data = b"Hello, world!\n";
let ciphertext = include_bytes!("../tests/data/data.txt.abcrypt");
let passphrase = "passphrase";

let cipher = Decryptor::new(&ciphertext, passphrase).unwrap();
let plaintext = cipher.decrypt_to_vec().unwrap();
source

pub const fn out_len(&self) -> usize

Returns the number of output bytes of the decrypted data.

Examples
let ciphertext = include_bytes!("../tests/data/data.txt.abcrypt");
let passphrase = "passphrase";

let cipher = Decryptor::new(&ciphertext, passphrase).unwrap();
assert_eq!(cipher.out_len(), 14);

Trait Implementations§

source§

impl<'c> Clone for Decryptor<'c>

source§

fn clone(&self) -> Decryptor<'c>

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<'c> Debug for Decryptor<'c>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'c> RefUnwindSafe for Decryptor<'c>

§

impl<'c> Send for Decryptor<'c>

§

impl<'c> Sync for Decryptor<'c>

§

impl<'c> Unpin for Decryptor<'c>

§

impl<'c> UnwindSafe for Decryptor<'c>

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