extern crate P256;

#[cfg(test)]
mod ecdhe {
    use std::fs::File;
    use std::io::Read;

    use P256::{gen_keys, gen_secret};

    fn get_random() -> [u32; 8] {
        let mut file = File::open("/dev/urandom").expect("Unable to access /dev/urandom");
        let mut buffer = vec![0; 32];
        file.read(&mut buffer).expect("Unable to access /dev/urandom");
        let mut rnd: [u32; 8] = [0u32; 8];
        for i in 0..8 { rnd[i] = buffer[4 * i] as u32 | (buffer[4 * i + 1] as u32) << 8 | (buffer[4 * i + 2] as u32) << 16 | (buffer[4 * i + 3] as u32) << 24; }
        return rnd;
    }

    #[test]
    fn test() {
        for i in 0..10 {
            let (a_private_key, a_public_key) = gen_keys(get_random());
            let (b_private_key, b_public_key) = gen_keys(get_random());
            let a_secret = gen_secret(a_private_key, b_public_key);
            let b_secret = gen_secret(b_private_key, a_public_key);
            assert_eq!(a_secret, b_secret);
        }
    }
}