fix: empty auth ranges (#1016)

This commit is contained in:
sinu.eth
2025-10-10 15:44:38 -07:00
committed by GitHub
parent 0ec2392716
commit 0a68837d0a
2 changed files with 13 additions and 0 deletions

View File

@@ -35,6 +35,11 @@ where
Self { map }
}
/// Returns `true` if the map is empty.
pub(crate) fn is_empty(&self) -> bool {
self.map.is_empty()
}
/// Returns the keys of the map.
pub(crate) fn keys(&self) -> impl Iterator<Item = Range<usize>> {
self.map

View File

@@ -168,6 +168,10 @@ fn alloc_plaintext(
) -> Result<ReferenceMap, PlaintextAuthError> {
let len = ranges.len();
if len == 0 {
return Ok(ReferenceMap::default());
}
let plaintext = vm.alloc_vec::<U8>(len).map_err(PlaintextAuthError::vm)?;
let mut pos = 0;
@@ -189,6 +193,10 @@ fn alloc_ciphertext<'a>(
plaintext: ReferenceMap,
records: impl IntoIterator<Item = &'a RecordParams>,
) -> Result<ReferenceMap, PlaintextAuthError> {
if plaintext.is_empty() {
return Ok(ReferenceMap::default());
}
let ranges = RangeSet::from(plaintext.keys().collect::<Vec<_>>());
let keystream = alloc_keystream(vm, key, iv, &ranges, records)?;