use orion::hazardous::ecc::x25519::key_agreement;
use orion::kex::{PrivateKey, PublicKey};
use orion::pwhash::{Password, hash_password, hash_password_verify};

fn main() {
    let password = Password::from_slice(b"hello_world").unwrap();
    let password_hash = hash_password(&password, 100, 1024).unwrap();
    println!("{}", password_hash.unprotected_as_encoded());
    println!("{:?}", hash_password_verify(&password_hash, &password));

    println!("{}", "-".repeat(88));

    let alice_sk = PrivateKey::generate();
    let alice_pk = PublicKey::try_from(&alice_sk).unwrap();

    let bob_sk = PrivateKey::generate();
    let bob_pk = PublicKey::try_from(&bob_sk).unwrap();

    let alice_shared = key_agreement(&alice_sk, &bob_pk).unwrap();
    let bob_shared = key_agreement(&bob_sk, &alice_pk).unwrap();

    println!("{}", hex::encode(alice_shared.unprotected_as_bytes()));
    println!("{}", hex::encode(bob_shared.unprotected_as_bytes()));

    println!("{}", "-".repeat(88));

    let user_password = Password::from_slice(b"hello_world").unwrap();
    let salt = orion::kdf::Salt::default();
    let derived_key = orion::kdf::derive_key(&user_password, &salt, 3, 1 << 16, 32).unwrap();
    println!(
        "{} {}",
        hex::encode(salt.as_ref()),
        hex::encode(derived_key.unprotected_as_bytes())
    );

    println!("{}", "-".repeat(88));

    let aead_key = orion::aead::SecretKey::generate(32).unwrap();
    let ciphertext = orion::aead::seal(&aead_key, b"hello world").unwrap();

    let plaintext = orion::aead::open(&aead_key, &ciphertext).unwrap();
    println!("{}", hex::encode(&ciphertext));
    println!("{} {}", hex::encode(&plaintext), String::from_utf8_lossy(&plaintext));
}
