diff --git a/tfhe/src/strings/assert_functions/mod.rs b/tfhe/src/strings/assert_functions/mod.rs index dba04c3f5e..f0f4f1e61b 100644 --- a/tfhe/src/strings/assert_functions/mod.rs +++ b/tfhe/src/strings/assert_functions/mod.rs @@ -87,7 +87,7 @@ impl Keys { pub fn assert_len(&self, str: &str, str_pad: Option) { let expected = str.len(); - let enc_str = FheString::new(&self.ck, str, str_pad); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); let start = Instant::now(); let result = self.sk.len(&enc_str); @@ -107,7 +107,7 @@ impl Keys { pub fn assert_is_empty(&self, str: &str, str_pad: Option) { let expected = str.is_empty(); - let enc_str = FheString::new(&self.ck, str, str_pad); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); let start = Instant::now(); let result = self.sk.is_empty(&enc_str); @@ -125,7 +125,7 @@ impl Keys { } pub fn assert_encrypt_decrypt(&self, str: &str, str_pad: Option) { - let enc_str = FheString::new(&self.ck, str, str_pad); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); let dec = self.ck.decrypt_ascii(&enc_str); @@ -144,8 +144,8 @@ impl Keys { ) { let expected = str.contains(pat); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string())); let start = Instant::now(); @@ -180,8 +180,8 @@ impl Keys { ) { let expected = str.ends_with(pat); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string())); let start = Instant::now(); @@ -216,8 +216,8 @@ impl Keys { ) { let expected = str.starts_with(pat); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string())); let start = Instant::now(); @@ -246,8 +246,8 @@ impl Keys { pub fn assert_find(&self, str: &str, str_pad: Option, pat: &str, pat_pad: Option) { let expected = str.find(pat); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string())); let start = Instant::now(); @@ -282,8 +282,8 @@ impl Keys { pub fn assert_rfind(&self, str: &str, str_pad: Option, pat: &str, pat_pad: Option) { let expected = str.rfind(pat); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string())); let start = Instant::now(); @@ -324,8 +324,8 @@ impl Keys { ) { let expected = str.strip_prefix(pat); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string())); let start = Instant::now(); @@ -374,8 +374,8 @@ impl Keys { ) { let expected = str.strip_suffix(pat); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string())); let start = Instant::now(); @@ -424,8 +424,8 @@ impl Keys { ) { let expected = str.eq_ignore_ascii_case(rhs); - let enc_lhs = FheString::new(&self.ck, str, str_pad); - let enc_rhs = GenericPattern::Enc(FheString::new(&self.ck, rhs, rhs_pad)); + let enc_lhs = FheString::new_trivial(&self.ck, str, str_pad); + let enc_rhs = GenericPattern::Enc(FheString::new_trivial(&self.ck, rhs, rhs_pad)); let clear_rhs = GenericPattern::Clear(ClearString::new(rhs.to_string())); let start = Instant::now(); @@ -452,8 +452,8 @@ impl Keys { } pub fn assert_comp(&self, str: &str, str_pad: Option, rhs: &str, rhs_pad: Option) { - let enc_lhs = FheString::new(&self.ck, str, str_pad); - let enc_rhs = GenericPattern::Enc(FheString::new(&self.ck, rhs, rhs_pad)); + let enc_lhs = FheString::new_trivial(&self.ck, str, str_pad); + let enc_rhs = GenericPattern::Enc(FheString::new_trivial(&self.ck, rhs, rhs_pad)); let clear_rhs = GenericPattern::Clear(ClearString::new(rhs.to_string())); // Equal @@ -504,7 +504,7 @@ impl Keys { result_message_clear_rhs(str, rhs, expected_ne, dec_ne, end.duration_since(start)); assert_eq!(dec_ne, expected_ne); - let enc_rhs = FheString::new(&self.ck, rhs, rhs_pad); + let enc_rhs = FheString::new_trivial(&self.ck, rhs, rhs_pad); // Greater or equal let expected_ge = str >= rhs; @@ -562,7 +562,7 @@ impl Keys { pub fn assert_to_lowercase(&self, str: &str, str_pad: Option) { let expected = str.to_lowercase(); - let enc_str = FheString::new(&self.ck, str, str_pad); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); let start = Instant::now(); let result = self.sk.to_lowercase(&enc_str); @@ -579,7 +579,7 @@ impl Keys { pub fn assert_to_uppercase(&self, str: &str, str_pad: Option) { let expected = str.to_uppercase(); - let enc_str = FheString::new(&self.ck, str, str_pad); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); let start = Instant::now(); let result = self.sk.to_uppercase(&enc_str); @@ -596,8 +596,8 @@ impl Keys { pub fn assert_concat(&self, str: &str, str_pad: Option, rhs: &str, rhs_pad: Option) { let expected = str.to_owned() + rhs; - let enc_lhs = FheString::new(&self.ck, str, str_pad); - let enc_rhs = FheString::new(&self.ck, rhs, rhs_pad); + let enc_lhs = FheString::new_trivial(&self.ck, str, str_pad); + let enc_rhs = FheString::new_trivial(&self.ck, rhs, rhs_pad); let start = Instant::now(); let result = self.sk.concat(&enc_lhs, &enc_rhs); @@ -614,7 +614,7 @@ impl Keys { pub fn assert_repeat(&self, str: &str, str_pad: Option, n: u16, max: u16) { let expected = str.repeat(n as usize); - let enc_str = FheString::new(&self.ck, str, str_pad); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); // Clear n let start = Instant::now(); @@ -641,7 +641,7 @@ impl Keys { assert_eq!(dec, expected); // Encrypted n - let enc_n = self.ck.encrypt_u16(n, Some(max)); + let enc_n = self.ck.trivial_encrypt_u16(n, Some(max)); let start = Instant::now(); let result = self.sk.repeat(&enc_str, &UIntArg::Enc(enc_n)); @@ -670,7 +670,7 @@ impl Keys { pub fn assert_trim_end(&self, str: &str, str_pad: Option) { let expected = str.trim_end(); - let enc_str = FheString::new(&self.ck, str, str_pad); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); let start = Instant::now(); let result = self.sk.trim_end(&enc_str); @@ -687,7 +687,7 @@ impl Keys { pub fn assert_trim_start(&self, str: &str, str_pad: Option) { let expected = str.trim_start(); - let enc_str = FheString::new(&self.ck, str, str_pad); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); let start = Instant::now(); let result = self.sk.trim_start(&enc_str); @@ -704,7 +704,7 @@ impl Keys { pub fn assert_trim(&self, str: &str, str_pad: Option) { let expected = str.trim(); - let enc_str = FheString::new(&self.ck, str, str_pad); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); let start = Instant::now(); let result = self.sk.trim(&enc_str); @@ -722,7 +722,7 @@ impl Keys { let mut expected: Vec<_> = str.split_ascii_whitespace().map(Some).collect(); expected.push(None); - let enc_str = FheString::new(&self.ck, str, str_pad); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); let mut results = Vec::with_capacity(expected.len()); @@ -769,8 +769,8 @@ impl Keys { ) { let expected = str.split_once(pat); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let start = Instant::now(); let (lhs, rhs, is_some) = self.sk.split_once(&enc_str, &enc_pat); @@ -797,8 +797,8 @@ impl Keys { ) { let expected = str.rsplit_once(pat); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let start = Instant::now(); let (lhs, rhs, is_some) = self.sk.rsplit_once(&enc_str, &enc_pat); @@ -820,8 +820,8 @@ impl Keys { let mut expected: Vec<_> = str.split(pat).map(Some).collect(); expected.push(None); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let mut results = Vec::with_capacity(expected.len()); @@ -858,8 +858,8 @@ impl Keys { let mut expected: Vec<_> = str.rsplit(pat).map(Some).collect(); expected.push(None); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let mut results = Vec::with_capacity(expected.len()); @@ -902,8 +902,8 @@ impl Keys { let mut expected: Vec<_> = str.split_terminator(pat).map(Some).collect(); expected.push(None); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let mut results = Vec::with_capacity(expected.len()); @@ -946,8 +946,8 @@ impl Keys { let mut expected: Vec<_> = str.rsplit_terminator(pat).map(Some).collect(); expected.push(None); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let mut results = Vec::with_capacity(expected.len()); @@ -990,8 +990,8 @@ impl Keys { let mut expected: Vec<_> = str.split_inclusive(pat).map(Some).collect(); expected.push(None); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let mut results = Vec::with_capacity(expected.len()); @@ -1036,8 +1036,8 @@ impl Keys { let mut expected: Vec<_> = str.splitn(n as usize, pat).map(Some).collect(); expected.push(None); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let mut results = Vec::with_capacity(expected.len()); @@ -1084,7 +1084,7 @@ impl Keys { assert_eq!(dec_as_str, expected); - let enc_n = self.ck.encrypt_u16(n, Some(max)); + let enc_n = self.ck.trivial_encrypt_u16(n, Some(max)); results.clear(); // Call next enough times @@ -1143,8 +1143,8 @@ impl Keys { let mut expected: Vec<_> = str.rsplitn(n as usize, pat).map(Some).collect(); expected.push(None); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let mut results = Vec::with_capacity(expected.len()); @@ -1191,7 +1191,7 @@ impl Keys { assert_eq!(dec_as_str, expected); - let enc_n = self.ck.encrypt_u16(n, Some(max)); + let enc_n = self.ck.trivial_encrypt_u16(n, Some(max)); results.clear(); // Call next enough times @@ -1249,10 +1249,10 @@ impl Keys { ) { let expected = str.replace(pat, to); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string())); - let enc_to = FheString::new(&self.ck, to, to_pad); + let enc_to = FheString::new_trivial(&self.ck, to, to_pad); let start = Instant::now(); let result = self.sk.replace(&enc_str, &enc_pat, &enc_to); @@ -1321,13 +1321,13 @@ impl Keys { let expected = str.replacen(pat, to, n as usize); - let enc_str = FheString::new(&self.ck, str, str_pad); - let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad)); + let enc_str = FheString::new_trivial(&self.ck, str, str_pad); + let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad)); let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string())); - let enc_to = FheString::new(&self.ck, to, to_pad); + let enc_to = FheString::new_trivial(&self.ck, to, to_pad); let clear_n = UIntArg::Clear(n); - let enc_n = UIntArg::Enc(self.ck.encrypt_u16(n, Some(max))); + let enc_n = UIntArg::Enc(self.ck.trivial_encrypt_u16(n, Some(max))); let start = Instant::now(); let result = self.sk.replacen(&enc_str, &enc_pat, &enc_to, &clear_n);