diff --git a/tfhe/examples/fhe_strings/ciphertext.rs b/tfhe/examples/fhe_strings/ciphertext.rs index 66105e409..2a50ccf87 100644 --- a/tfhe/examples/fhe_strings/ciphertext.rs +++ b/tfhe/examples/fhe_strings/ciphertext.rs @@ -113,7 +113,7 @@ impl FheString { // Converts a `RadixCiphertext` to a `FheString`, building a `FheAsciiChar` for each 4 blocks. // Panics if the uint doesn't have a number of blocks that is multiple of 4. - pub fn from_uint(uint: RadixCiphertext) -> FheString { + pub fn from_uint(uint: RadixCiphertext, padded: bool) -> FheString { let blocks_len = uint.blocks().len(); assert_eq!(blocks_len % 4, 0); @@ -132,8 +132,7 @@ impl FheString { FheString { enc_string: ascii_vec, - // We are assuming here there's no padding, so this isn't safe if we don't know it! - padded: false, + padded, } } @@ -195,14 +194,14 @@ mod tests { let enc = FheString::new(&ck, str, Some(7)); let uint = enc.to_uint(&sk); - let mut converted = FheString::from_uint(uint); + let mut converted = FheString::from_uint(uint, false); converted.set_is_padded(true); let dec = ck.decrypt_ascii(&converted); assert_eq!(dec, str); let uint_into = enc.into_uint(&sk); - let mut converted = FheString::from_uint(uint_into); + let mut converted = FheString::from_uint(uint_into, false); converted.set_is_padded(true); let dec = ck.decrypt_ascii(&converted); diff --git a/tfhe/examples/fhe_strings/server_key/mod.rs b/tfhe/examples/fhe_strings/server_key/mod.rs index 5b05456f3..c73244b9e 100644 --- a/tfhe/examples/fhe_strings/server_key/mod.rs +++ b/tfhe/examples/fhe_strings/server_key/mod.rs @@ -237,7 +237,7 @@ impl ServerKey { self.key .if_then_else_parallelized(condition, &true_ct_uint, &false_ct_uint); - let mut result = FheString::from_uint(result_uint); + let mut result = FheString::from_uint(result_uint, false); if padded { result.set_is_padded(true); } else if potentially_padded { @@ -269,7 +269,7 @@ impl ServerKey { &shifted, ); - FheString::from_uint(result) + FheString::from_uint(result, false) } fn right_shift_chars(&self, str: &FheString, shift: &RadixCiphertext) -> FheString { @@ -292,7 +292,7 @@ impl ServerKey { &shifted, ); - FheString::from_uint(result) + FheString::from_uint(result, false) } }