pub struct Decryptor<'c> { /* private fields */ }Expand description
Decryptor for the abcrypt encrypted data format.
Implementations§
source§impl<'c> Decryptor<'c>
impl<'c> Decryptor<'c>
sourcepub fn new(
ciphertext: &'c impl AsRef<[u8]>,
passphrase: impl AsRef<[u8]>
) -> Result<Self>
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:
ciphertextis 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();sourcepub fn decrypt(&self, buf: impl AsMut<[u8]>) -> Result<()>
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();sourcepub fn decrypt_to_vec(&self) -> Result<Vec<u8>>
Available on crate feature alloc only.
pub fn decrypt_to_vec(&self) -> Result<Vec<u8>>
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();sourcepub const fn out_len(&self) -> usize
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§
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> 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