//! Parse an encoded, encrypted chunk.
//!
//! This is basically a benchmark, but doesn't require nightly Rust.

use obnam::{chunk::*, cipher::*, plaintext::*};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let engine = Engine::new(EngineKind::Aead, Key::default());
    let plaintext = Plaintext::uncompressed("hello, world".as_bytes());
    let mut factory = MetadataFactory::default();
    let meta = factory.from_label("data-chunk")?;
    let chunk = Chunk::data(DataChunk::encrypt(&engine, &plaintext, meta.clone())?);
    let data = chunk.serialize()?;

    let n: usize = std::env::args().nth(1).unwrap().parse()?;
    println!("parse chunk {n} times");
    for _ in 0..n {
        Chunk::parse(&data).unwrap();
    }

    Ok(())
}
