Skip to main content

decrypt

Function decrypt 

Source
pub fn decrypt<R, W>(
    input: R,
    output: W,
    password: &PasswordString,
) -> Result<(), AescryptError>
where R: Read, W: Write,
Expand description

Decrypt an Aescrypt file (v0–v3) — zero secret exposure, maximum security

§Thread Safety

This function is thread-safe and can be called concurrently from multiple threads. All operations are pure (no shared mutable state), making it safe to:

  • Spawn in threads for parallel processing
  • Use with async runtimes (spawn_blocking)
  • Implement cancellation by wrapping in a thread and joining/detaching as needed

§Performance

For large files, this operation may take significant time. In release mode, expect:

  • ~158 MiB/s throughput for decryption
  • Processing time scales linearly with file size

Users requiring cancellation should spawn this function in a thread and implement their own cancellation mechanism (e.g., using channels or thread handles).

§Example: Threaded Usage

use aescrypt_rs::{decrypt, PasswordString};
use std::io::Cursor;
use std::thread;

let password = PasswordString::new("secret".to_string());
let encrypted = b"encrypted data...";

// Spawn decryption in a thread
let handle = thread::spawn(move || {
    let mut plaintext = Vec::new();
    decrypt(Cursor::new(encrypted), &mut plaintext, &password)
});

// Can wait for completion or implement cancellation
let result = handle.join().unwrap();