refactor(fhe_strings): add padded param to from_uint

This commit is contained in:
Mayeul@Zama
2024-10-17 13:24:19 +02:00
committed by mayeul-zama
parent 5056e06380
commit aebc2619b2
2 changed files with 7 additions and 8 deletions

View File

@@ -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);

View File

@@ -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)
}
}