Skip to main content

smart_decode

Function smart_decode 

Source
pub fn smart_decode(
    stego_bytes: &[u8],
    passphrase: &str,
) -> Result<(PayloadData, DecodeQuality), StegoError>
Expand description

Unified decode: auto-detects Ghost or Armor mode from the embedded frame.

Tries Ghost first, then Armor. Returns the decoded payload and quality info.

When the parallel feature is enabled, Ghost and Armor decodes run concurrently via rayon::join, roughly halving decode latency on multi-core devices.

Examples found in repository?
examples/test_link.rs (line 22)
12fn main() {
13    let args: Vec<String> = std::env::args().collect();
14    let path = args.get(1).map_or("/tmp/phasm_shared.jpg", |s| s.as_str());
15    let img = std::fs::read(path).unwrap_or_else(|e| {
16        eprintln!("Error reading {path}: {e}");
17        std::process::exit(1);
18    });
19    eprintln!("Image: {} bytes", img.len());
20    let start = Instant::now();
21    eprintln!("Trying empty passphrase...");
22    match smart_decode(&img, "") {
23        Ok((p, _q)) => eprintln!("SUCCESS (empty): text='{}' [{:.1}s]", p.text, start.elapsed().as_secs_f64()),
24        Err(e) => eprintln!("FAILED (empty): {:?} [{:.1}s]", e, start.elapsed().as_secs_f64()),
25    }
26}