fix(integer): handle message mod 0 in num_blocks

This commit is contained in:
Nicolas Sarlin
2025-12-09 09:36:20 +01:00
committed by Nicolas Sarlin
parent c083eb826d
commit f17cd9bd37

View File

@@ -25,6 +25,9 @@ impl DataKind {
Self::Unsigned(n) | Self::Signed(n) => n.get(),
Self::Boolean => 1,
Self::String { n_chars, .. } => {
if message_modulus.0 == 0 {
return 0;
}
let blocks_per_char = 7u32.div_ceil(message_modulus.0.ilog2());
(n_chars * blocks_per_char) as usize
}
@@ -95,3 +98,20 @@ impl Expandable for BooleanBlock {
}
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_string_num_blocks() {
let kind = DataKind::String {
n_chars: 10,
padded: true,
};
let num_blocks = kind.num_blocks(MessageModulus(0));
assert_eq!(num_blocks, 0);
}
}