use aes::{cipher::KeyInit, Aes128}; use prop_test::prelude::*; use squint::Id; pub fn any_cipher() -> impl Strategy { any::<[u8; 16]>().prop_map(|key| Aes128::new(&key.into())) } fn id_to_string_and_back(id: i64, cipher: &Aes128) -> squint::Result { Id::::new(id, cipher) .to_string() .parse() .and_then(|id: Id| id.to_raw(cipher)) } #[test] fn id_decodes_back() { prop_test!(&(any::(), any_cipher()), |(id, cipher)| { let parsed = id_to_string_and_back::<0>(id, &cipher); prop_assert!(parsed.is_ok()); prop_assert_eq!(id, parsed.unwrap()); Ok(()) }); }