mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-08 22:28:01 -05:00
chore(fhe_strings): add encryption-decryption test
This commit is contained in:
@@ -125,6 +125,17 @@ impl Keys {
|
||||
assert_eq!(dec, expected);
|
||||
}
|
||||
|
||||
pub fn assert_encrypt_decrypt(&self, str: &str, str_pad: Option<u32>) {
|
||||
let enc_str = FheString::new(&self.ck, str, str_pad);
|
||||
|
||||
let dec = self.ck.decrypt_ascii(&enc_str);
|
||||
|
||||
println!("\n\x1b[1mEncrypt/Decrypt:\x1b[0m");
|
||||
result_message(str, str, &dec, Duration::from_nanos(0));
|
||||
|
||||
assert_eq!(str, &dec);
|
||||
}
|
||||
|
||||
pub fn assert_contains(
|
||||
&self,
|
||||
str: &str,
|
||||
|
||||
@@ -140,6 +140,15 @@ fn test_is_empty() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encrypt_decrypt() {
|
||||
let keys = Keys::new();
|
||||
|
||||
for (str, str_pad) in TEST_CASES_MATCH {
|
||||
keys.assert_encrypt_decrypt(str, Some(str_pad));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_contains() {
|
||||
let keys = Keys::new();
|
||||
|
||||
@@ -105,6 +105,8 @@ fn main() {
|
||||
keys.assert_len(str, str_pad);
|
||||
keys.assert_is_empty(str, str_pad);
|
||||
|
||||
keys.assert_encrypt_decrypt(str, str_pad);
|
||||
|
||||
keys.assert_contains(str, str_pad, pat, pat_pad);
|
||||
keys.assert_ends_with(str, str_pad, pat, pat_pad);
|
||||
keys.assert_starts_with(str, str_pad, pat, pat_pad);
|
||||
|
||||
Reference in New Issue
Block a user