//! Hash function demonstration: SHA-256, SHA3-256, and SHAKE256.
//!
//! ```sh
//! cargo run -p arcana --release --example hash_demo
//! ```

use arcana::hash::sha3::{Sha3_256, Shake256};
use arcana::hash::sha256::Sha256;
use arcana::{Hasher, Xof};

fn hex(bytes: &[u8]) -> String {
    bytes.iter().map(|b| format!("{:02x}", b)).collect()
}

fn main() {
    let msg = b"hello, arcana";

    // SHA-256 (FIPS 180-4) — 32-byte digest
    let digest = Sha256::hash(msg);
    println!("SHA-256:    {}", hex(&digest));
    assert_eq!(digest.len(), 32);

    // SHA3-256 (FIPS 202) — 32-byte digest
    let digest = Sha3_256::hash(msg);
    println!("SHA3-256:   {}", hex(&digest));
    assert_eq!(digest.len(), 32);

    // Streaming: feed in chunks
    let mut h = Sha256::new();
    h.update(b"hello, ");
    h.update(b"arcana");
    let digest2 = h.finalize();
    println!("SHA-256 streaming: {}", hex(&digest2));
    assert_eq!(digest2, Sha256::hash(msg));

    // SHAKE256 (FIPS 202) — extendable output, here 64 bytes
    let mut xof = Shake256::new();
    xof.update(msg);
    let mut out = [0u8; 64];
    xof.squeeze(&mut out);
    println!("SHAKE256 (64B): {}", hex(&out));

    println!("\nAll hash demos passed.");
}
